Business Background
/home/pms
Directory is the working directory, now the directory is too large to take up hard disk space, need to clean up, now need to enumerate all the directories in the directory of more than 200MB sub-file directory, and the sub-file directory occupies space
Script Implementation
du -h --max-depth=10 /home/pms/* | awk ‘{ if($1 ~ /M/){split($1"M")}; if(($1 ~ /G/) || ($1"%-10s %s\n"$1$2} }‘ | sort -n -r
which
-h--max-depth=10 /home/pms/*
The results are as follows
$ 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...
The following awk statement is the function of judging the first argument, making a string match, and, if it is M, intercepting by the character M
if($1/M/){split($1"M")};
The following awk statement is the function of judging the first parameter and making a string match:
M, determine if the capacity is greater than 200MB, is the direct output parameter 1 and parameter 2
G, direct output parameter 1 and parameter 2
if(($1/G/) || ($1/M/ && arr[1]>200"%-10s %s\n"$1$2}
Output Results
$ du -h --max-depth=10‘{ 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/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...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Linux] combines awk to enumerate all file directories larger than the specified capacity size