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.
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!
I use sudo su