November 03, 2019
!! is a quick way to repeat a command in a UNIX environment.
ls is probably not a great exampel of a command that needs this shortcut, you can imagine if the command is long and you don’t want to type it all out again, how it can come in handy.
Another place where the
!! can come in handy is when repeating a command as the super user.
Since we’re probably not running around as the
root user most of the time, if we want to do something that requires those permissions, we need to be explicit and prefix the command with
Then, if the user is part of the
sudo group, the command will execute.
For example, imagine printing the auth logs on a server:
$ cat /var/log/auth.log cat: /var/log/auth.log: Permission denied
Since my user actually is part of the super user group, I do have permission to view the file, I just need to be explicit.
sudo the command…
$ sudo cat /var/log/auth.log [sudo] password for stephen:
That is, I prefix the command with
sudo and then type out the whole command again (and risk a typo), or, I could just use the
$ sudo !! [sudo] password for Stephen:
Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!