Use This Terminal Command When You Forget To Type Sudo

Use This Terminal Command When You Forget to Type Sudo

Sometimes, when you're working in the command line, you need to enter "sudo" to assume root privileges for a given task. You may not always remember, but one little trick can save you from retyping your last command with "sudo" prefixed to it.

Just type this:

sudo !!

This will initiate the previous command with sudo in front of it, and you'll be immediately asked for your password. This saves you a good amount of frustration — at least if you make this mistake as often as I do.

For more awesome time-saving shortcuts, check out our guide.

Terminal 101: 5 Time-saving Tips and Tricks [MacLife]


Comments

    at least if you make this mistake as often as I do.

    Adam Dachis.

    does this work in linux? or just macos?

      Yes. Well, bash, csh, tcsh, probably ksh, but not a genuine vanilla sh.

    Oh my giddy aunt, this will save me approximately as much time as I saved when I first learned to Alt-tab! Thanks for that!

Join the discussion!

Trending Stories Right Now