View advanced Sort options, Quick Reference Help Alias

alias sorth='sort --help|sed -n "/^ *-[^-]/s/^ *\(-[^ ]* -[^ ]*\) *\(.*\)/\1:\2/p"|column -ts":"'
Once you get into advanced/optimized scripts, functions, or cli usage, you will use the sort command alot. The options are difficult to master/memorize however, and when you use sort commands as much as I do (some examples below), it's useful to have the help available with a simple alias. I love this alias as I never seem to remember all the options for sort, and I use sort like crazy (much better than uniq for example). # Sorts by file permissions find . -maxdepth 1 -printf '%.5m %10M %p\n' | sort -k1 -r -g -bS 20% 00761 drwxrw---x ./tmp 00755 drwxr-xr-x . 00701 drwx-----x ./askapache-m 00644 -rw-r--r-- ./.htaccess # Shows uniq history fast history 1000 | sed 's/^[0-9 ]*//' | sort -fubdS 50% exec bash -lxv export TERM=putty-256color Taken from my
Sample Output
[1766:1762 0:30073] 06/10/10 [ +1] ~/dr/pepper
(1:30073)$ sorth
-b, --ignore-leading-blanks    ignore leading blanks
-d, --dictionary-order         consider only blanks and alphanumeric characters
-f, --ignore-case              fold lower case to upper case characters
-g, --general-numeric-sort     compare according to general numerical value
-i, --ignore-nonprinting       consider only printable characters
-M, --month-sort               compare (unknown) < `JAN' < ... < `DEC'
-n, --numeric-sort             compare according to string numerical value
-r, --reverse                  reverse the result of comparisons
-c, --check                    check whether input is sorted; do not sort
-k, --key=POS1[,POS2]          start a key at POS1, end it at POS2 (origin 1)
-m, --merge                    merge already sorted files; do not sort
-o, --output=FILE              write result to FILE instead of standard output
-s, --stable                   stabilize sort by disabling last-resort comparison
-S, --buffer-size=SIZE         use SIZE for main memory buffer
-t, --field-separator=SEP      use SEP instead of non-blank to blank transition
-T, --temporary-directory=DIR  use DIR for temporaries, not $TMPDIR or /tmp;
-u, --unique                   with -c, check for strict ordering;
-z, --zero-terminated          end lines with 0 byte, not newline

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? 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.


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: