What does the command "sudo !!" mean?

51

7

I saw the command

sudo !!

in a video.

What does this mean?

mko

Posted 2011-02-19T18:54:40.110

Reputation: 869

10Run the previous command with sudo. – The Pixel Developer – 2011-02-19T18:55:21.437

Related. – Paused until further notice. – 2011-02-19T19:05:00.173

3@jmort253: SU, etc., is intended to be the font of all knowledge. Google is simply the search engine that leads here. We don't do RTFM except as a supplement to a usable answer. – Paused until further notice. – 2011-02-19T19:06:42.057

Furthermore there is enough documentation on a linux distribution. Learn how to use commands like info and man. If you have them installed man COMMAND will give you information on what the command does like man sudo. If you don't have it installed install apt-file with sudo apt-get install apt-file then you can search with apt-file which packet contains the man command (if you are using debian or derivate of debian). – Darokthar – 2011-02-19T19:19:30.803

@jmort253: I'd love to see how you Google "!!". – Wooble – 2011-02-19T19:20:16.843

@All - My apologies! I thought the OP just had a typo and was asking what sudo meant. sudo !!, with the exclamation points, now that's an interesting question. sudo without the exclamation points, just Google it as that's been answered dozens of times. My confusion was based on not clearly reading the question! +1 to the OP! – jmort253 – 2011-02-19T21:10:26.173

9It means Sudo with a vengeance! If two machines are close by (2-3 inches), you can actually run commands on the other machine with this. It's that strong. – Pekka – 2011-02-19T21:46:37.100

@The Pixel Developer: why don't you post your answer as an actual answer, instead of a comment? – dag729 – 2011-02-19T22:10:24.563

@dag729 I didn't think it was worth it. – The Pixel Developer – 2011-02-20T02:54:29.690

Answers

62

From the bash manual:

9.3.1 Event Designators

!! - Refer to the previous command. This is a synonym for ‘!-1’.

And from the sudo man page:

sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.

So, sudo !! means to execute the previous command as the superuser.

Carl Norum

Posted 2011-02-19T18:54:40.110

Reputation: 2 621

5Congratulations for the only response that actually answers the question. – Daniel Beck – 2011-02-19T19:11:02.813

1So to emphasize this: !! is a history-function of the shell, and not in any way bound to sudo. You may use it everywhere where it makes sense. – user unknown – 2011-02-19T22:19:17.183

Thanks for telling, get the "superuser" part? – Ja5087 – 2011-04-06T08:42:33.217

10

The double exclamation point "!!" is used to recall the last line entered into a shell. sudo is shorthand for "Super User DO" and is used when you want to execute a function with super user privileges.

So if I executed

./foobar

but then remembered I needed super user privelages, one could simply type

sudo !!

rather than typingsudo ./foobar all the way out. This is particularly useful when your last command was on the order of dozens of characters.

Peaches491

Posted 2011-02-19T18:54:40.110

Reputation: 261

That's not accurate. From Wikipedia (citing good references): It originally stood for "superuser do" as the older versions of sudo were designed to run commands only as the superuser. However, the later versions added support for running commands not only as the superuser but also as other (restricted) users, and thus it is also commonly expanded as "substitute user do"..

– Pablo A – 2018-04-15T15:23:42.950