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
man history!to a matching command in the current shell's history list.!!is a special case, equivalent to!-1, where a negative numbernfollowing!refers to the nth previous command.LESS='+/^HISTORY EXPANSION' man bash.