1

In our environment, we have an NFS mount which contains all users home directories.

I want to find the users whose home directories sizes are greater than 10G and send a notification to them. I tried:

du -sh * | sort -hr   

This worked like a charm, but I could not find the command to extract the directories of size > 10 G.

I tried find . -size +10G -exec ls -lhS {} \; but it didn't work.

What's the best way to find/extract the directories with size greater than 10G?

3

This should do it.

Where the first column (size) exceeds 10gb, output the second column (directory name)

du -sk * | awk '$1 > 10485760 { print $2 }'

Or as requested, to show in human readable form, as below. The regular expression ensures column 1 ends in a G (gigabytes) and the substr part strips the final letter from column 1 and looks to see if it's more than 10.

du -sh * | awk '$1 ~ /G$/ && substr($1,0,length($1)-1) > 10 { print $0 }'

Example:

du -sh *
2.5G    steve
du -sh * | awk '$1 ~ /G$/ && substr($1,0,length($1)-1) > 1 { print $0 }'
2.5G    steve
du -sh * | awk '$1 ~ /G$/ && substr($1,0,length($1)-1) > 3 { print $0 }'
(no output)
  • 1
    Thanks Steve. This is very helpful. But by any chance, can we change list it in human readable format? Preferably like, 21G mark 17G kannan 15G harry – Kannan AnandaKrishnan Aug 10 '15 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.