Need to free up space on your linux box? Find files by size in the easiest way possible.

So, you are out of space on your linux box. You know you have a bunch of stuff floating around on there. You just need an easy way to query it and locate the junk. So, here it is. I will give you the command and then break-down exactly what it does.

$find /.m2/ -type f -size +10000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nrk 2,2

Now lets look at what it does:

find /.m2/ -type f -size +10000k

Here we’re searching the home directory of the user you’re currently logged in as for files greater than 10MB.

-exec ls -lh {} \; 2> /dev/null

 

This redirects all permission errors (since we are not root) when doing the locate.

awk '{ print $NF ": " $5 }'

 

This will display the path and size of the files in a human readable way.

sort -nrk 2,2

This sorts from large to small.

And that is it. Pretty straight forward. But, god is it a time saver.