Numerically sorted human readable disk usage

du -s * | sort -n | cut -f2 | tr '\n' '\0' | xargs -0 -I {} du -sh "{}"
This approach deals with special characters such as apostrophe and whitespace in the file/directory names. tr '\n' '\0' converts the newline delimiting into NUL delimitering which xargs -0 expects. It works on systems which do not yet support xargs -d or sort -h, and includes files in addition to directories.
Sample Output
8.0K	[
8.0K	cat
8.0K	domainname
8.0K	echo
8.0K	expr
8.0K	hostname
8.0K	kill
8.0K	link
8.0K	mkdir
8.0K	mv
8.0K	pwd
8.0K	rm
8.0K	rmdir
8.0K	sleep
8.0K	sync
8.0K	wait4path
 12K	chmod
 12K	cp
 12K	date
 12K	dd
 12K	df
 12K	rcp
 12K	stty
 20K	ls
 20K	ps
 28K	ed
 36K	launchctl
 56K	pax
196K	csh
328K	zsh
348K	bash
348K	sh
748K	ksh

0
2014-11-23 18:56:10

6 Alternatives + Submit Alt

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: