Recursively find disk usage, sort, and make human readable (for systems without human-readable sort command)

du -x ${SYMLINKS} -k "$@" | sort -n | tail -100 | awk 'BEGIN { logx = log(1024); size[0]= "KB"; size[1]= "MB"; size[2]= "GB"; size[3]= "TB" } { x = $1; $1 = ""; v = int(log(x)/logx); printf ("%8.3f %s\t%s\n",x/(1024^v), size[v], $0) }'
Recursively find disk usage, sort, and make human readable: * For systems without human-readable sort command * awk, not perl
Sample Output
   3.148 MB	 ./arch/cris/include
   3.426 MB	 ./arch/cris
   3.539 MB	 ./arch/blackfin
   4.539 MB	 ./arch/mips/include/asm
   4.543 MB	 ./arch/mips/include
   5.398 MB	 ./arch/mips
   9.543 MB	 ./drivers
  11.230 MB	 ./arch/arm
  13.852 MB	 ./include/linux
  21.820 MB	 ./include
  46.758 MB	 ./arch
  84.902 MB	 .

0
By: dpanofsky
2015-08-27 23:16:25

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: