I just needed to find the largest files in a folder (in an attempt to find out why it was so bloody huge!) and have ended up with the following handy combination of commands…
find /path/to/folder -size +1M -print0 | xargs -0 du -h | sort -nr
This simply lists all the files in the path specified where the size is more then 1Mb (you can use k (kilobyte), M (megabyte) and G (gigabyte) too) and prints the list out using null bytes as row terminators. The reason for null bytes is so whitespace characters don't break the next section, xargs. The xargs function allows you to run a command using the piped in value as an argument to the command, in this case we want to know the human readable size of the file. Finally we do a numeric (-n) reverse (-r) sort.
1 Comments
Also finding largest folders
I also needed to find the largest folders in a folder recently and stumbled across a handy
gawkscript on the linuxquestions.org forum… Check this out!du -sb * | sort -rn | gawk '{ hum[1024**3]="Gb";hum[1024**2]="Mb";hum[1024]="Kb"; for (x=1024**3; x>=1024; x/=1024) { if ($1 >= x) { printf "%.2f %s \t %s\n", $1 / x, hum[x], $2; break } } }'Firstly, it does a "Disk Usage summary with bytes size", then pipes that to
sortwhich does a numeric reverse sort. That is then piped into gawk which has a neat little script which does a Kb/Mb/Gb conversion on the bytes "column".Post new comment