Reuse the last argument of the previous command with !$
:
$ echo abc def abc def $ echo !$ def
A common use case would be mkdir
and cd
:
$ mkdir foo $ cd !$
You can also insert the last argument of the previous command and continue typing with <ESC>.
:
$ echo abc def abc def $ echo <ESC>. ghi def ghi
Oh, the little things… 🙂
One even less known nifty thing is that the last argument is also available in the bash command prompt using Alt+’.’. This is nifty in cases where you want to re-use the argument, but slightly edit it. Also, you can cycle through the history of last arguments by repeatedly pressing Alt+’.’ — something that !$ does not provide.
Another useful trick: !:1 expands to first argument of last command, !:2 is the second, etc.