6 July 2008

Bash history shortcuts

Many people who sit with me at a computer have questions about the strange incantations that I type into the terminal. I often use shell techniques like grabbing the last argument to the previous command:

$ ls ~/src/atlassian/confluence/trunk
$ cd !$

Or using the output of the last command as an argument to this one:

$ find . -name ConfluenceActionSupport.properties
$ vi `!!`

Two weeks ago, if you wanted to understand how this works, I would have referred you to the man page, and showed you the two or three tricks I know. But now, Allan Odgaard has written a thorough and very readable article on the subject: Working with history in bash.

I won’t try to summarise it here. If you’re interested in improving your bash fu, be sure to read it.