Saturday, August 18, 2007

Sudo !! the previous command

Ever try to do something that requires root access and realize you're not root when you get the line: "Permission denied"?

Well now you can `sudo` that previous command by using:
/ $prompt>`cp /root/.bashrc .`
cp: cannot stat `/root/.bashrc': Permission denied
/ $prompt>`sudo !!`
sudo cp /root/.bashrc .

What about if you hosed up the last argument of a command:
`rn /huge/long/path/to/file` instead of `rm` or you used `dc` instead of `cd`

Well now you can simply use `!$` and viola, you've got your last argument:

/ $prompt>`dc /huge/long/path/
/ $prompt> (That didn't do much)
/ $prompt> `cd !$`
/huge/long/path $prompt>

Shortcut Screencast Contest: Sudo !! the previous command - Lifehacker

No comments: