Finding the largest files in a folder

Jan
06
2009
Tagged in , , &

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.

Comment Icon

1 Comments

The most recent comment was on Wed, 17th Jun 2009, 08:11

Also finding largest folders

I also needed to find the largest folders in a folder recently and stumbled across a handy gawk script 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 sort which 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

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <img> <p>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You can enable syntax highlighting of source code with the following tags: <pre>, <code>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Follow Me

Recent comments

Answers 1 day ago
Replies.... 6 days ago
Or in 6 days ago
A few tweaks 1 week ago
Nice 1 week ago
Thanks a million 1 week ago
Syndicate content