The Computer Oracle

What does the command "sudo !!" mean?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Horror Game Menu Looping

--

Chapters
00:00 What Does The Command &Quot;Sudo !!&Quot; Mean?
00:11 Accepted Answer Score 68
00:39 Answer 2 Score 10
01:03 Thank you

--

Full question
https://superuser.com/questions/247894/w...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#commandline #unix #sudo

#avk47



ACCEPTED ANSWER

Score 68


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.




ANSWER 2

Score 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.