Recursively find top 20 largest files (> 1MB) sort human readable format

find . -type f -print0 | xargs -0 du -h | sort -hr | head -20
Search for files and list the 20 largest. find . -type f gives us a list of file, recursively, starting from here (.) -print0 | xargs -0 du -h separate the names of files with NULL characters, so we're not confused by spaces then xargs run the du command to find their size (in human-readable form -- 64M not 64123456) | sort -hr use sort to arrange the list in size order. sort -h knows that 1M is bigger than 9K | head -20 finally only select the top twenty out of the list
Sample Output
64M	./icons/gnome/icon-theme.cache
23M	./fonts/extra-fonts/arialuni.ttf
22M	./libpinyin/data/bigram.db
21M	./fonts/cjkuni-uming/uming.ttc
20M	./anthy/anthy.dic
18M	./mythes/th_en_US_v2.dat
17M	./fonts/wqy-zenhei/wqy-zenhei.ttc
14M	./icons/hicolor/icon-theme.cache
14M	./icons/Faenza/icon-theme.cache
8.3M	./cracklib/pw_dict.pwd
6.2M	./mm-common/doctags/libstdc++.tag
6.2M	./libhangul/hanja/hanja.txt
5.4M	./icons/Mist/icon-theme.cache
4.8M	./gir-1.0/Gtk-3.0.gir
4.8M	./dict/linux.words
4.4M	./gir-1.0/Gtk-2.0.gir
4.3M	./anthy/zipcode.t
4.0M	./fonts/un-core/UnDotumBold.ttf
3.9M	./opencc/simp_to_trad_phrases.ocd
3.8M	./tor/geoip

By: flatcap
2012-03-30 10:21:12

1 Alternatives + Submit Alt

What Others Think

Too new for my system :o sort -hr sort: invalid option -- 'h' Try `sort --help' for more information.
bashrc · 535 weeks ago
@bashrc: Really? Sorry, it's been in Gnu sort since 2009 (v7.5).
flatcap · 534 weeks and 6 days ago
@flatcap: On RedHat/CentOS 5 this doesn't work.
Doskias · 318 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: