nice disk usage, sorted by size, see description for full command

du -sk ./* | sort -nr
full command below, would not let me put full command in text box du -sk ./* | sort -nr | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t%s\n",int(x*10)/10,pref[y],$2); } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
Sample Output
22.6M	./NVIDIA-Linux-x86-185.18.31-pkg1.run
152K	./ffmpeginstall.3.2.1
28K	./compiz-check
16K	./ffmpeginstall.3.2.1.tar.gz
8K	./Desktop
4K	./Videos
4K	./Templates
4K	./Public
4K	./Pictures
4K	./Music
4K	./Documents
4K	./cpanel_rebuildbindzones

4
By: op4
2010-02-04 04:08:05

What Others Think

Works great... Tried to set that as bash alias but that doesn't work for me... How do you use it?
georgz · 556 weeks ago
Obligatory mention of ncdu if an interactive ncurses-based program isn't out of the question: http://dev.yorhel.nl/ncdu package 'ncdu' in debian/ubuntu.
bwoodacre · 556 weeks ago
sudo du -skh ./* | sort -nr
ab · 555 weeks and 1 day ago
du -skch ./* | sort -nr -c gives the total -h makes it human readable Did I miss something or a simple 'man du' would have save 3 line of awk ??
log0 · 555 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?

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: