If you’re like me, you never want to lose a command. I’m constantly searching back through them to find out just what those command line flags were, what the esoteric command is (and where it’s located), and most of all: what in Tcl’s name did I do last month when I installed foobazzulator. First thing to know: control-r.

However, bash ships with a ridiculously short memory: 500 commands. That’s not enough: right now, my powerbook’s iTerm prompt is:

[/Users/jwellons]
111280$

Go into your .bash_profile now and add these lines, before you read on:

HISTFILESIZE=1000000000
HISTSIZE=1000000

Unless you’re very precocious, that should square you away for about 10 years (I’m at about 22 months since enlightenment).

Once you develop control-r as a fast way to search your command history, you’ll notice immediate stress relief, and as I do everyday, wish you’d done this years before.

Now that you have commands piling up, you can do more than just use them. You can analyze them too, for fun and profit (since time = money)!

The basic starter is

cut -f1 -d" " .bash_history | sort | uniq -c | sort -nr | head -n 30

In other words, just what do you spend so much time typing? Here’s the money: Anything in at least the top ten, assuming it is not from somHistory can be browsed using arrow commands, but more efficient way is to use Ctrl-R for anything but previous half-dozen of commands. Ctrl-R mechanism provides search in history: typed characters can be in any place of the command will autocomplete as soon as there’s a match to a history entry, then you just need to hit enter to reexecute the command -time splurge, needs to be aliased to a one or two letter shorthand.

My top command is v for vim, which I’ve executed 9225 times. If those two extra letters, which require me to switch hands, then use adjacent fingers take an extra half-second each time: that’s well over an hour wasted! And what a terribly drudgerous and unhealthy hour it is too: mindlessly typing im 9225 times!

Even worse, who knows how desperately I needed to open that file, and yet I needed to type superfluous characters, probably messing them up on the first three tries.

Actually, that’s only my second highest command. cl tops the list at 11116. You see, last time I did this analysis, I noticed I was spending (yes, spent, like lines of code, there is no glory in using a lot of them) many commands first cd‘ing to a directory, then listing the contents. Here’s cl:

# Compress the cd, ls -l series of commands.
alias lc="cl"
function cl () {
   if [ $# = 0 ]; then
      cd && ll
   else
      cd "$*" && ll
   fi
}

There you have it, accompanied by its most common typo. Add this to your bash profile now, and you’ll add several hours to your life. Hurry! Don’t wait! It may not seem like much now, but no one lies on her deathbed wishing she had spent more time first changing directories, waiting for it to return, then typing ls.

Since I know you’re dying to see the rest, here’s my whole thirty, unaliased for readability:

11116 cl
9225 vim
7833 ll
The alias of ll depends on the OS I’m on, but for my Mac, it’s ls -AGlFT.
5145 cd
4858 clear
4563 rm
3950
alias to log into the master db server at my old workplace
3740 lt
version of ll that puts most recently modified stuff at the bottom. Mandatory! Add -tr to ll above
3435 mod
a function that does lt, but runs it through tail
3236 mv
2103 ls
1887 grep
1863 perl
1834 df
1767 mzscheme
1679
alias to log into my personal server
1580 g++
1544 cat
1186 scp
1080 find
988 man
925 echo
921 mkdir
907 sudo
888 history
841
alias to log into the dev server at my old workplace
831 cp
763 gpg
758 locate
733 gzip
 

Depending on response, we may do another section with pie charts, finding all the typo permutations for simple commands (there’s a lot), and searching for common sequences.

What I really want to see, though, is your top commands.