What is the purpose of sudo bang bang (sudo !!
) and when might one need to use it?
instead of typing arrow-up, scrolling to the beginning of the line, adding sudo and hitting enter (imagine scrolling through those loooong apt-get commands). So many seconds gained! Yay! There are many other bang-commands such as !
Under the hood, bang (!) commands introduce commands from your bash history list into the input stream. This feature makes it easy to repeat commands, substitute text, manipulate arguments, and fix typos in your previous commands quickly.
sudo means run the following command (on the same line) as another user (usually the superuser.) Unless I'm wrong, this isn't quite right. Running a command with sudo does not change which user is running the command.
The bang bang (!!
) command is a shortcut to repeat 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 !!
instead of typing arrow-up, scrolling to the beginning of the line, adding sudo
and hitting enter (imagine scrolling through those loooong apt-get
commands). So many seconds gained! Yay!
There are many other bang-commands such as !x
, !?x
, !!:p
and !!*
. This blog post lists them and explains what they are for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With