55

I saw the command

sudo !!

in a video.

What does this mean?

Tamara Wijsman
  • 57,083
  • 27
  • 185
  • 256
mko
  • 959
  • 3
  • 9
  • 13
  • 10
    Run the previous command with sudo. – The Pixel Developer Feb 19 '11 at 18:55
  • [Related](http://superuser.com/questions/247834/how-to-write-a-script-to-sudo-the-last-command). – Dennis Williamson Feb 19 '11 at 19:05
  • 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. – Dennis Williamson Feb 19 '11 at 19:06
  • 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 Feb 19 '11 at 19:19
  • @jmort253: I'd love to see how you Google "!!". – Wooble Feb 19 '11 at 19:20
  • @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 Feb 19 '11 at 21:10
  • 9
    It 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 Feb 19 '11 at 21:46
  • @The Pixel Developer: why don't you post your answer as an actual answer, instead of a comment? – dag729 Feb 19 '11 at 22:10
  • @dag729 I didn't think it was worth it. – The Pixel Developer Feb 20 '11 at 02:54

2 Answers2

67

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
  • 2,353
  • 2
  • 21
  • 20
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.

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
Peaches491
  • 261
  • 1
  • 8
  • 1
    That's not accurate. From [Wikipedia](https://en.wikipedia.org/wiki/Sudo#References) (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 Apr 15 '18 at 15:23