[Linux]结合awk列举大于指定容量大小所有文件目录

本文发布时间: 2019-Mar-22
业务背景/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', $1, $2} }' | sort -n -r其中du -h --max-depth=10 /home/pms/*结果如下$ du -h --max-depth=10 /home/pms/*0 /home/pms/addressCountMap12K /home/pms/bigDataEngine/conf1.7M /home/pms/bigDataEngine/analysis/warning33M /home/pms/bigDataEngine/analysis/log...下面这个awk语句,作用是判断第一个参数,进行字符串匹配,如果是M的话,按字符M进行截取if($1 ~ /M/){split($1, arr, 'M')};下面这个awk语句,作用是判断第一个参数,进行字符串匹配:M,判断容量是否大于200MB,是则直接输出参数1和参数2G,直接输出参数1和参数2 if(($1 ~ /G/) || ($1 ~ /M/ && arr[1]>200)) {printf '%-10s %s', $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', $1, $2} }' | sort -n -r 1018M /home/pms/recsys/algorithm/schedule/project/mixproduct948M /home/pms/recsys/algorithm/schedule/project/contentbasedrelatedproduct940M /home/pms/recsys/algorithm/schedule/project/view_after_viewing/cf922M /home/pms/new_product_import913M /home/pms/db_engine903M /home/pms/recsys/algorithm/schedule/project/campus862M /home/pms/recsys/algorithm/schedule/project/company/user...


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:09pm
栏目列表