Quickly sudo-ing the previous command in Bash Shell
So, you probably have run into this scenario where you forget to type
sudo before your command that requires root privileges. For instance, the
apt-get install command.
When you do this, the bash terminal would give you the following error.
So, to run this command with sudo what you would normally do is go back to that command and prepend
sudo to it, right? Not anymore.
sudo !! ✨
There’s a better and quick way to do it with just one command. Check it out.
$ sudo !!
What this command will do is it will run the previously run command with
sudo so you don’t need to go back to the command and prepend or type the command all the way from scratch.
It’s just a nifty little command that can improve your workflow dramatically.
But be aware that this command only works in Bash-based shell. So, that’s the only caveat you need to know.