You can get any parameter of the previous command by using "Esc, <number>, Esc, .". If you repeat pressing "Esc, ." you get the n-th parameter from the command before the previous one, etc.
More details in this Stackoverflow answer: http://stackoverflow.com/a/4010170/578588
It's actually Meta, emulated by an ESC character by the terminal. OSX tip: check "use Option as Meta" in Terminal's preferences, and you can keep Option pressed while you mash ".".
Which is fine if you never need to generate characters using the Option key. For example on a German keyboard you need the Option key to write { or }.
I'm on a french layout so I know :-)
It also has the side effect of "resurrecting" dead keys (which are unrelated to Option), making input of 'ê'and 'ï' impossible.
An alternative is using iTerm2 which has a similar setting, liberally applyable to either Option key.
You can also use the following options to see and edit all expansions before running a command:
shopt -s histverify histreeditI prefer `alt+.`, which does the same thing without having to reach for the ESC key.
I use `!:p` to the same effect. Which has the benefit that you can insert a history number between the bang! and the colon: ( set PS1 to include the command number if you do this a lot ).
There are some great tips/tricks in this document. Too bad it's not in Markdown or something easier on the eyes!
Markdown-ified version: http://www.notehub.org/kywfm
Editing password is hackernews if anyone wants to tune up the markdown.
In bash, "ESC" then "." fetches the last parameter of the previous command. It's invaluable (same as typing "!$" but you get to see and edit it)