What does `!!` mean in `sudo !!`?

!! in bash is an alias for the previous command (see Event Designators). So it re-runs the previous command with sudo permissions.


sudo bang bang is a very useful command when working in Command Line Interface.

Some Linux distros have you login as a user instead of an administrator.

So, to do something admin-wise, you have to proceed the command with sudo (Super-User DO), which tells the system “you will do this, because I said so.” The !! / bang-bang (! = bang) is basically a shortcut you can use to repeat the previous command.

So, typical scenario is that you try a command, and it kicks back a message saying you have to be an admin to do that. So, you can either type sudo to run that command as super-user/admin, or you can type sudo !! where !! tells the system to use the previous command that was attempted.UfH

There are many other bang-commands. For a list of them and explanations to what they are, check out Linux Bang Commands, see also Bash history and bang commands


The bang bang (!!) command is a shortcut to repeat and run the previous command you entered in your terminal. This command is very useful when you forget that you need admin rights to make a certain action, and lets you repeat it with super-user rights just by typing,

sudo !!

!! grabs the last run command.

For example:

apt-get update

The output will be,

E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

After that,if we run sudo !! command,the output will be

Hit http://extras.ubuntu.com saucy/main amd64 Packages
Get:3 http://mirror.sov.uk.goscomb.net saucy-updates Release.gpg [933 B]
Hit http://ppa.launchpad.net saucy Release                                  
Hit http://extras.ubuntu.com saucy/main i386 Packages 
Hit http://mirror.sov.uk.goscomb.net saucy Release                             
99% [Waiting for headers] [Waiting for headers] [Waiting for headers]

Which means !! part grabs the previous run command apt-get update and the preceeding sudo part makes the command to run with superuser rights.

And how the sudo !! runs the previous command with superuser privileges means,normally all the commands we entered on the terminal are stored in the command history.Run the history command on the terminal,it shows all the commands you entered.The !! part in the sudo !! grabs the last command stored in the command history and the whole sudo !! runs the last command with admin privileges.

Some other bang commands are explained in this blog post.