[Linux] combines awk to enumerate all file directories larger than the specified capacity size

Source: Internet
Author: User

Business Background

/home/pmsDirectory 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.