How often have you typed in a command in your linux shell, and then realized that you forgot to type sudo, so you end up with an error or editing the dreaded read-only file? This happens to me much more than I'd like to admit, so I'm writing about it.
You have a couple of options, the easiest one is to just use !! to tell bash to use the last command.
For instance, if you tried to type this, you'd get an error that you are editing a read-only file:
vi /etc/apt/sources.list
Once that happens, then you can just use this command:
sudo !!
Which bash will then expand into this command:
sudo vi /etc/apt/sources.list
An alternative method would be to just hit the up arrow key, hit either the Home key or Ctrl+A, and then type sudo.

Categories
- GNU/Linux (20)
- Linux Security (12)
- Ubuntu Tutorials (20)
- Web Browsers (1)
- Windows 2000 (20)
- Windows 2003 (13)
- Windows 7 (8)
- Windows Vista (43)
- Windows XP (54)
Bookmark us
Tuesday, July 8, 2008
Add Sudo to Your Last Bash Command With "!!" Syntax
Posted by
Tutorialsland Staff
at
4:30 PM
Labels: Ubuntu Tutorials
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment