GNU sort's -h option

December 31, 2012

I only recently became aware of GNU sort's -h option, which strikes me as a beautiful encapsulation of everything (both good and bad) that people attribute to GNU programs and their profusion of options.

GNU sort's -h is like -n (sort numerically) except that it sorts numerically for GNU's 'humane' numbers, as produced by (for example) GNU du's -h option. This leads naturally to a variant of a little script that I've already talked about:

du -h | sort -hr | less

On the one hand, -h is clearly useful in both commands. Humane numbers are a lot easier to read and grasp than plain numbers, and now GNU sort will order them correctly for you. On the other hand you can see the need for a -h argument to sort as evidence of an intrinsic problem with du -h; in this view, GNU is piling hack on top of hack. The arguable Unix way might be a general hum command that humanized all numbers (or specific columns of numbers if you wanted); that would make the example into 'du | sort -nr | hum | less', which creates a general tool at the price of making people add an extra command to their pipelines.

I don't have any particular view on whether GNU sort's -h option is Unixly wrong or not. I do think that it's (seductively) convenient, and now that I've become aware of it it's probably going to work its way into various things I do.

(This could spark a great debate on what the true Unix way is, but I'm not going to touch that one right now.)

Written on 31 December 2012.
« What I'd have liked to hear about Python 3 from the developers
How our fileserver infrastructure is a commodity setup (and inexpensive) »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Dec 31 03:12:33 2012
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.