What exactly is sudo bang bang?

LinuxBashTerminalSh

Linux Problem Overview


What is the purpose of sudo bang bang (sudo !!) and when might one need to use it?

make me a sandwich, sudo bang bang

Linux Solutions


Solution 1 - Linux

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!

sudo bang bang

There are many other bang-commands such as !x, !?x, !!:p and !!*. This blog post lists them and explains what they are for.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionalestanisView Question on Stackoverflow
Solution 1 - LinuxalestanisView Answer on Stackoverflow