Last Updated: February 25, 2016
·
1.392K
· jmarizgit

Are you missing "sudo" on commands in terminal? Don't worry.

Sometimes you are in your terminal and need to type a command that requires you to have root powers. Well I don't know you, but I sometimes forget to put sudo in front of those commands. Look at this example:

$ rm somefile
rm: somenewfile: Permission denied

I have some options here. I could retype the entire command or use arrow up and go to the beginning of the line adding "sudo" to it. But a better way to fix my mistake is using the operator "!!". Like this:

$ rm somefile
rm: somenewfile: Permission denied
$ sudo !!
$ sudo rm newfile 

Amazing, your file "newfile" is now removed.
Enjoy.

2 Responses
Add your response

The history expansion character (! by default in bash) can do lots of cool things:

http://www.thegeekstuff.com/2011/08/bash-history-expansion/
Formal reference:
http://www.gnu.org/software/bash/manual/bashref.html#History-Interaction

over 1 year ago ·

this is great :') thank you!

over 1 year ago ·