Ever forgotten to run the last command with sudo at the beginning? Here’s how to re-run the command with sudo at the beginning, without re-typing the whole thing:
For instance, if you originally did this, but got an error:
Then you’d just run the sudo !! command, and it would actually run:
sudo rm filename
That’s all there is to it.
This works because !! is a shortcut way to pull up an item from the bash history. You could use !-1 for the same thing, or !-2 to re-run the command before the last one.