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.
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 08/2/10