/home/pms目录是工作目录,现在该目录占用硬盘空间过大,需要清理,现在需要列举该目录中所有大于200MB的子文件目录,以及该子文件目录的占用空间
脚本实现 du -h --max-depth=10 /home/pms/* | awk '{ if($1 ~ /M/){split($1, arr, "M")}; if(($1 ~ /G/) || ($1 ~ /M/ && arr[1]>200)) {printf "%-10s %s\n", $1, $2} }' | sort -n -r其中
du -h --max-depth=10 /home/pms/*结果如下
$ du -h --max-depth=10 /home/pms/* 0 /home/pms/addressCountMap 12K /home/pms/bigDataEngine/conf 1.7M /home/pms/bigDataEngine/analysis/warning 33M /home/pms/bigDataEngine/analysis/log ...下面这个awk语句,作用是判断第一个参数,进行字符串匹配,如果是M的话,按字符M进行截取
if($1 ~ /M/){split($1, arr, "M")};下面这个awk语句,作用是判断第一个参数,进行字符串匹配:
M,判断容量是否大于200MB,是则直接输出参数1和参数2
G,直接输出参数1和参数2
if(($1 ~ /G/) || ($1 ~ /M/ && arr[1]>200)) {printf "%-10s %s\n", $1, $2} 输出结果 $ du -h --max-depth=10 /home/pms/* | awk '{ if($1 ~ /M/){split($1, arr, "M")}; if(($1 ~ /G/) || ($1 ~ /M/ && arr[1]>200)) {printf "%-10s %s\n", $1, $2} }' | sort -n -r 1018M /home/pms/recsys/algorithm/schedule/project/mixproduct 948M /home/pms/recsys/algorithm/schedule/project/contentbasedrelatedproduct 940M /home/pms/recsys/algorithm/schedule/project/view_after_viewing/cf 922M /home/pms/new_product_import 913M /home/pms/db_engine 903M /home/pms/recsys/algorithm/schedule/project/campus 862M /home/pms/recsys/algorithm/schedule/project/company/user