tags:

views:

67

answers:

4

Is there a way in Bash to recall the argument of the previous command?

I usually do vi file.c followed by gcc file.c. Is there a way in Bash to recall the argument of the previous command?

+8  A: 

You can use $_ or !$ to recall the last argument of the previous command.

Also Alt + . can be used to recall the last argument of any of the previous commands.

codaddict
Also, if you want an arbitrary argument, you can use `!!:1`, `!!:2`, etc. (`!!:0` is the previous command itself.) See http://www.gnu.org/software/bash/manual/bashref.html#History-Interaction
janmoesen
Or see `man bash` ;)
jeremiahd
+1  A: 

Yes, you can use !$ to recall the last argument of the preceding command.

Justin Ethier
+2  A: 

If the previous command had two arguments, like this

ls a.txt b.txt

and you wanted the first one, you could type

!:1

giving

a.txt

Or if you wanted both, you could type

!:1-2

giving

a.txt b.txt

You can extend this to any number of arguments, eg:

!:10-12
Robert Gowland
+1  A: 

In the command line you can press "esc-dot". It cicles the previous arguments you used.

Antonio Mano