Very useful when you forget a sudo at the beginning of your command, !!
acts like an alias of the previous command. Example :
$ mv /very/long/path/for/a/protected/sensible/file/caution.h .
(...) Permission denined
$ sudo !!
sudo mv /very/long/path/for(...) .
[sudo] password :
- How do we call that double
!!
trick ?
Researches over internet are difficult because of that token. - How does it work ? I suspect a link with the history command.
- Where it is defined ? Can I define some other myself ?
EDIT : Some interesting event designators
!!:*
It refers to the arguments of the previous command.
Use case :
cat /a/file/to/read/with/long/path
nano !!:*
:p
Just print the command without executing it, you have to put it at the end of the event designator.
$ !-5:p
sudo rm /etc/fstab -f
Best Answer
!!
is listed in thebash
manual under the heading "Event Designators":So
!!
will be replaced with the previous command.Note that the shell history will not contain the literal
!!
but instead the actual command that was executed: