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
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.
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
Sweet…
[…] 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..
Confirmed on:
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)..
(1) http://savannah.gnu.org/patch/?2565
(2) http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commit;h=159faba1376ffd5a46fe4bbc780d85dd3e502cea
(3) http://packages.debian.org/search?keywords=coreutils
(4) http://directory.fsf.org/project/coreutils/
(5) http://packages.gentoo.org/package/sys-apps/coreutils