Monday, December 22, 2008

Recall last argument of last command in bash shell


I have already posted about how we can access the last argument of the last command in bash shell using bash !$

Here is one more alternative and easy to type way

Its the keystroke Alt . (alt and dot)

e.g.

$ mkdir -p /tmp/newdir/anotherdir

$ cd [Alt].

$ pwd
/tmp/newdir/anotherdir

5 comments:

Braden said...

Very cool. I love your simple tricks like this--and I even have a good chance of remembering these for when I need them, unlike your awk wizardry. :)

Unknown said...

@bawb, thanks, I will try to post more tricks. Thanks.

atoztoa said...

$_ will be replaced with the last argument of last command.

Also try $1, $2 ...

Adithya Kiran said...

One can use "Esc+." combination too.:), however, "alt+." is much simpler way

Adithya Kiran said...

Hey Jadu,

Few additions to your tip. If you want to have last argument you press "Alt+.", if you want the command name, hit "alt+0+.", first argument "alt+1+.", second argument "alt+2+." and so on so forth.

Eg:

# vimdiff a.txt b.txt
If you type "ALT+0+." it will print "cat"

"ALT+1+." it will print a.txt and so on

and finally, ALT+2+. or ALT+. results b.txt to be printed

© Jadu Saikia www.UNIXCL.com