du -s * 2>/dev/null | sort -n | cut -f2 | xargs du -sh 2>/dev/null
That’s a good one! It fails for files/dirs with spaces in the name. According to xargs man page, it’ll accept a delimiter such as the new line character. With that it can handle spaces:
du -s * | sort -n | cut -f2 | xargs -d “\n” du -sh
[...] liked Jason’s solution of passing a file list to du via xargs to produce results sorted by size in human readable format, [...]
GNU sort has a -h option that makes this trivial:
du -hs * | sort -h
Sounds promising, but sort complains that -h is an invalid option on most Linuxes I use..
CentOS 5.4 — sort (GNU coreutils) 5.97
Debian 5.0.3 — sort (GNU coreutils) 6.10
Ubuntu 8.10 — sort (GNU coreutils) 6.10
Ubuntu 9.10 — sort (GNU coreutils) 7.4
Is there a popular distro that carries the new version of sort (-h)?
Looks like this option was added in 7.5 (1) in May 2009 (2) — so it’s quite new. So only distros which package new stuff very aggressively would have it (or distros without package management — are there any?).
Wonder what distro redondos runs..
In Debian, looks like it just missed making it into the testing branch, so you’d have to grab 8.1 from unstable (3). This means it’ll probably show up in Ubuntu within the next couple of releases.
Latest stable version of corutils from GNU is 8.4 (4). Perhaps there are other useful features that would make it worthwhile to install from source. Although according to “apt-cache showpkg coreutils”, a ton of other packages depend on coreutils so I’d be fearful of introducing an undiscovered bug and breaking a lot of stuff. I think Debian’s cautious approach to slowly promoting packages from experimental branch to unstable > testing > stable has a lot of merit.
Looks like 7.5 is in Gentoo stable (5)..
Jason Sares is a Giant Dork