//View Tip #26
Similar Tips
» Permanent bash history
» Up/down arrow keys for searching history
» Use history to SUDO last command
» Stream shell commands to Twitter
» See your favorite commands


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Running a second command with the same arguments as the previous command, use '!*' to repeat all arguments or '!:2' to use the second argument. '!$' uses the final argument.

$ cd /home/user/foo

cd: /home/user/foo: No such file or directory
$ mkdir !*
mkdir /home/user/foo

View Comments »


Add your comment

Comments are currently disabled
To get last argument of previous command simply hit ESC and dot (<ESC> .)
A little bit more convenient than !* since this way you can edit if you want.
Posted 2008-10-20 19:41:55
In BASH, Alt-. will do this same thing as well, and it's event slightly more conventient that Esc-., due to keyboard layout.
Posted 2009-02-19 19:08:08
!^ is the first argument of the previous commandline and !! is the entire line.  "man history" has a lot of other useful stuff as well.

You can also cause readline to expand history escapes when you hit space by adding the following to ~/.inputrc

$if Bash
   Space: magic-space
Posted 2009-03-02 21:08:53
not working in AIX 5 with KSH shell.Instead a directory named !* got created.

/home/bb47056> cd aaa
ksh: aaa:  not found
/home/bb47056> mkdir !*
/home/bb47056> cd aaa
ksh: aaa:  not found
Posted 2009-09-15 04:24:08
just use keyboard pointer....
Posted 2010-03-02 02:00:09

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit