Wednesday·24·November·2010
Useful but Unknown Unix Commandline Options: sort -h //at 01:12 //by abe
The GNU coreutils command “du” knows about the option “-h” to output human readable (or at least human friendly) values with unit prefixes, e.g. k, M or G.
The GNU coreutils command “sort” also can sort by numbers for quite a long time using the option “-n”, but that doesn’t work on the output of “du -h”. So you usually just did one of the following commands, but couldn’t easily combine them:
$ du -h $ du | sort -n
For approximately a year, GNU sort now knows about another command line option named “-h”. You guessed it probably: “sort -h” can sort human readable values with SI prefixes, e.g.
$ du -h | sort -h | tail -15 34M ./ttf-mplus-033/debian/ttf-mplus 34M ./ttf-mplus-033/debian/ttf-mplus/usr 34M ./ttf-mplus-033/debian/ttf-mplus/usr/share 34M ./ttf-mplus-033/debian/ttf-mplus/usr/share/fonts 34M ./ttf-mplus-033/debian/ttf-mplus/usr/share/fonts/truetype 34M ./ttf-mplus-033/debian/ttf-mplus/usr/share/fonts/truetype/ttf-mplus 35M ./ttf-mplus-034 57M ./ttf-mplus-029 60M ./php5-5.2.6/ext 60M ./ttf-mplus-030 63M ./ttf-mplus-031 65M ./ttf-mplus-032 67M ./ttf-mplus-033 81M ./php5-5.2.6 1.5G . $
You can get this feature already in Debian Unstable (Sid) and Testing
(Squeeze, the upcoming stable release), and Ubuntu Maverick and Natty,
but not yet in the current Debian Stable release (Lenny) nor in
the last Ubuntu LTS release (Lucid Lynx).
Tagged as: Debian, Debian Testing, Debian Unstable, du, GNU Coreutils, Lenny, Lucid, Maverick, Natty, nuggets, SI, Sid, sort, Squeeze, Ubuntu, UUUCO, UUUT
// show without comments // write a comment