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
Labels:
Bash,
bash shell,
bash shell newbie,
bash tricks,
Linux Commands
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
5 comments:
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. :)
@bawb, thanks, I will try to post more tricks. Thanks.
$_ will be replaced with the last argument of last command.
Also try $1, $2 ...
One can use "Esc+." combination too.:), however, "alt+." is much simpler way
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
Post a Comment