Find top 10 largest files in /var directory (subdirectories and hidden files included )

tree -isafF /var|grep -v "/$"|tr '[]' ' '|sort -k1nr|head
Should work even when very large files exist.

4
By: knoppix5
2016-05-27 16:41:20

2 Alternatives + Submit Alt

What Others Think

ls -l | sort -rn -k5,5 | nl | head -10 # 10 largest files in current dir
mpb · 176 weeks and 2 days ago
It does not find hidden files (name start with dot)
jiananmail · 175 weeks and 6 days ago
@jiananmail: Corrected, thank you for the comment!
knoppix5 · 175 weeks and 5 days ago
Poses a problem for large files for me. Removed the head from the below command to find out why my largest file was not showing up. My largest file was gamma.rpcthread (very bottom) tree -isafF . |grep -v "/$"|sort -k2nr [ 37476484] ./T2 [ 34284540] ./delta.rpc.2016-03-23.xz [ 32219572] ./delta.rpc.2016-03-22.xz [ 15979692] ./meta.zone [ 11610162] ./rpcthread.03.22.minimal [ 5565253] ./sulli [ 1455629] ./TEMP/gamma.exception.log [ 395896] ./gamma.exception [ 300906] ./O2S160409.posts [ 288115] ./O2S160409_update.posts [ 60246] ./whitelisted [ 45608] ./restrict-4.7.0.1.js [ 44211] ./restrict-4.5.0.7.js [ 28185] ./receipt.genshi.fo [ 9575] ./TEST1 [ 7092] ./sonde.py* [ 6915] ./lame.py* [ 5908] ./tgLayout.py [ 2628] ./shellshocktest* [ 24] ./test . [ 0] ./file1* [179714780] ./100g-200g 1 directory, 23 files [5609953143] ./gamma.rpcthread Did a quick mod ...maybe not the best and not as pretty... any better feedback is welcomed tree -isfF . | grep -v "/$"| sed -e "s/\[ */\[ /g" | sort -k2nr [ 5609953143] ./gamma.rpcthread [ 179714780] ./100g-200g [ 37476484] ./T2 [ 34284540] ./delta.rpc.2016-03-23.xz [ 32219572] ./delta.rpc.2016-03-22.xz [ 15979692] ./meta.zone [ 11610162] ./rpcthread.03.22.minimal [ 5565253] ./sulli [ 1455629] ./TEMP/gamma.exception.log [ 395896] ./gamma.exception [ 300906] ./O2S160409.posts [ 288115] ./O2S160409_update.posts [ 60246] ./whitelisted [ 45608] ./restrict-4.7.0.1.js [ 44211] ./restrict-4.5.0.7.js [ 28185] ./receipt.genshi.fo [ 9575] ./TEST1 [ 7092] ./sonde.py* [ 6915] ./lame.py* [ 5908] ./tgLayout.py [ 2628] ./shellshocktest* [ 24] ./test . [ 0] ./file1* 1 directory, 23 files
abacosis · 173 weeks and 2 days ago
@hahasun201 try to play with sort's -t option (field-separator) or tree's -h (human readable way for file sizes).
knoppix5 · 173 weeks and 1 day ago
Another way is the use of find: find /var -type f -printf "%s\t%p\n" | sort -rn | head -10
sesom42 · 172 weeks and 5 days 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: