Run the last shell command with sudo - Mac OS X
Haven't you had that moment when you type in a long command and forgot you needed to run it as root, gah!!!
There is a simple shortcut to save us from copy pasting or typing it all over again.
To run the last command 'as is', you can just do
$ !!
If you want to run it as root, with sudo; just do
$ sudo !!
Written by Rishav Rastogi
Related protips
3 Responses
Nice!
over 1 year ago
·
More generically, if you need to re-run the next-to-last command, you can use '!-2', or the Nth previous command with '!-N'. Or, if you review your command history ('history | tail -20'), and see that you need to re-run the 134th command in your history, '!134'.
over 1 year ago
·
@dougal :) Didn't know that. Cheers, Thanks.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#