Car insurance
Home > English, Software > bash: reuse last argument from previous command

bash: reuse last argument from previous command

January 14th, 2011 Leave a comment Go to comments

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… :-)

Categories: English, Software Tags:
  1. Ford Prefect
    January 30th, 2011 at 15:54 | #1

    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.

  1. No trackbacks yet.