Run the last command as root

sudo !!
Useful when you forget to use sudo for a command. "!!" grabs the last run command.

1203
By: root
2009-01-26 10:26:48

6 Alternatives + Submit Alt

What Others Think

This one might be my most commonly used "one liner". I even wrote a post about it in my blog ;)
JackiesJungle · 675 weeks ago
Doesn't this only work under ZSH ?
pyrho · 674 weeks and 6 days ago
doesnt seem to work under bash/centos4?
trix · 674 weeks and 5 days ago
work on Ubuntu 8.04
mrbyte · 674 weeks and 5 days ago
works on fedora with bash!
betsubetsu · 674 weeks and 1 day ago
I almost never use sudo. It promotes bad security: using the same password for root and and for regular users.
grep · 674 weeks ago
This command owns all. chmod 755 foo.bar operation not permitted sudo !! sudo chmod 755 foo.bar [sudo] password for waldo: (insert text of elation here)
farglenargle · 673 weeks and 3 days ago
works in bash/Debian !!
prayer · 672 weeks and 6 days ago
I love you. Befor I'v been so pissed off after typing long stings of command, and then have forgotten sudo. Therefor having to go all the way to the beginning of the command and enter sudo. Love it
Meeko · 671 weeks and 2 days ago
@meeko "All the way to the beginning"? Just hit the HOME key. Life is short! :-) sudo is great for sandwich making also: http://www.xkcd.com/149/
mpb · 670 weeks and 6 days ago
lots of the machines we use don't do home key - they do ~ instead - go figure. this could be very usefull. Thanks. I use !$ a lot. repeats the last word in the previous command e.g. ping nslookup !$ will translate to nslookup obviously the first ! grabs the previous line, and the second character does somnething else - ! grabs the first word, $ grabs the last word. anyone know any other variants or where to look up the man page - er... is it regexp or part of sh or perl or what??? ('scuse my ignorance - the unix needs a reverse lookup database)
bulwynkl · 670 weeks and 2 days ago
Regarding using the "home" key to get to the beginning of a command.. I just wanted to note, that you can almost always use "Ctrl-A" to jump to the beginning of the line in Bash and many other programs. I think it's part of libreadline? Also, if you're using Bash in a Screen session, use Ctrl-A twice to jump to the beginning of a line.
cmang · 670 weeks and 1 day ago
The HOME key is a single key press. Why chose a two key sequence instead of one?
mpb · 669 weeks and 6 days ago
I love this because it always feels like I'm yelling at my computer. do_something # i don't wanna... SUDO!! # ok, fine...
isaacs · 669 weeks and 3 days ago
I vote this down, because 'sudo' is not meant to be used in this way. Totally bad security practice! Even if you are the only user in your computer, you are advised to put only those commands that are safe and commonly used in the sudoers file. Otherwise, you are probably going to learn it in a hard way.
jxy · 669 weeks and 1 day ago
And I vote it up, because this -is- how sudo is intended to be used in many modern systems such as Ubuntu and OS X.
qubyte · 667 weeks and 4 days ago
I use Ctrl+p, Ctrl+a, sudo before.
kylexlau · 662 weeks and 4 days ago
OK, this inspired me to patch xkcd-149 :) http://www.vanginderachter.be/2009/patched-xkcd-149-make-me-a-sandwich/
svg · 658 weeks and 6 days ago
This is great!
marcop · 643 weeks and 4 days ago
Should work under bash, but you may have it disabled (set -H or set -o histexpand to reenable)
unixmonkey6345 · 643 weeks and 3 days ago
nice
haven489 · 626 weeks ago
I wrote an article about this and other popular one-liners. See it here: http://www.catonmat.net/blog/top-ten-one-liners-from-commandlinefu-explained/
pkrumins · 618 weeks and 4 days ago
pretty good
deargodzw · 618 weeks and 3 days ago
Explained the next 10 top one-liners: http://www.catonmat.net/blog/the-next-ten-one-liners-from-commandlinefu-explained/
pkrumins · 617 weeks and 4 days ago
Worky fine, OS X Snow Leopard 10.6.3.
hced · 613 weeks and 4 days ago
before I found `sudo !!` I used to do the following: 1) arrow up (to get the last command from history) 2) Ctrl+A (to put the cursor at the front of the command) 3) type "sudo " and hit enter
jemptymethod · 588 weeks and 6 days ago
WTF ? This is the best command for everyone ? Damn ubuntu lamers...
gormux · 578 weeks and 4 days ago
Don't listen to the "Sudo promotes bad security" types. You know what promotes worse security? Actually operating as root.
Karunamon · 529 weeks and 5 days ago
awesome
jldbasa · 520 weeks ago
@jemptymethod me too
dfang · 494 weeks and 6 days ago
Works in OS X Mountain Lion 10.8.1
delete · 489 weeks and 3 days ago
this command trick and many like it are part of the history command. try man history for more variants if your shell does not have history it wont work
bulwynkl · 482 weeks and 1 day ago
this command trick and many like it are part of the history command. try man history for more variants if your shell does not have history it wont work
bulwynkl · 482 weeks and 1 day ago
safer to type: /usr/bin/sudo !! For *any* command that will prompt for a password, it is more secure to type the full path (or pull it from shell history) because a common hack technique, if they can get access to your account, is to mess with your $PATH and plant a spoofed sudo which captures your typed password, prints an error message, and then execs the real sudo. The user thinks "Oh, I miss-typed the password. I'll type it again".
mpb · 364 weeks and 3 days ago
xkcd got it wrong (https://xkcd.com/149/) make me a sandwich what? make it yourself sudo!!
jemptymethod · 188 weeks and 2 days ago
Good post. I learn something new and challenging on sites I stumble upon on a daily basis. www.cuponism.com.my
broomhaylie · 76 weeks and 5 days ago
The post was quite enticing once I started I couldn’t stop reading, there was a similar piece I read before, and when comparing these two I think this one clearly comes out on top. https://www.cuponism.com.sg/
chengdale · 72 weeks and 4 days ago
home health care waco tx I got lost good thing I found this site!
yeoyeo · 62 weeks and 2 days ago
Who doesn't use this at least once a day LOL
tg0000 · 50 weeks and 6 days ago
cant get over this. will recommend this to my friends. painters billings mt
looneyhans · 48 weeks and 4 days ago
Everything is very open with a very clear explanation of the challenges. It was truly informative. Your site is very useful. Thanks for sharing! You must see this https://bendhvacpros.com
jackslesly19 · 45 weeks and 3 days ago
Toto Site Sports Toto Safety Playground Boatman Slot Site Overseas Soccer Sports Relay Tesla Price Korean Air Cho Hyun-ah Manman Celltrion Corona Vaccine Son Heung-min-gol Private Toto Recommended Microslot Sports Analysis Olvet Toto Boatmanhttps://bebe40.com/score https://bebe40.com/oversea https://linktr.ee/safety.toto https://toto-site.medium.com
totosite40 · 28 weeks and 6 days ago
X-Byte Enterprise Solution is a leading blockchain, AI, & IoT Solution company in USA and UAE, We have expert Web & mobile app development services Know more here: https://www.xbytesolutions.com 1s
bhaveshparekh · 28 weeks and 3 days ago
X-Byte Enterprise Solution is a leading blockchain, AI, & IoT Solution company in USA and UAE, We have expert Web & mobile app development services Know more here: https://www.xbytesolutions.com
bhaveshparekh · 28 weeks and 3 days ago
A great piece that sheds much needed light on Mobile App Development Company and its impact on business as there are many new details you posted here. Sometimes it is not so easy to build a "Mobile App" without custom knowledge; here you need proper development skills and experience. However, the details you mention here would be very much helpful for the beginner. Here is yet another top-notch solution provider “X-Byte Enterprise Solutions” who render feasible and credible solutions to global clients. Know more here: https://www.xbytesolutions.com/mobile-application-development-company.php
bhaveshparekh · 28 weeks and 3 days ago
This Just In: LeBron James is dropped from Nike and Picked up by SKETCHERS… new LeBRon James Shape UPs on the way!|tonydavisthedj| http://xbox-exclusive-best-selling-consoles.xyz/">Xbox Exclusive
seoperson · 27 weeks and 5 days ago
stevefalc · 27 weeks ago
seo what is seo search engine optimization
seofox · 17 weeks and 6 days ago
seo what is seo search engine optimization
seofox · 17 weeks and 6 days ago
seo what is seo search engine optimization
seofox · 17 weeks and 6 days ago
If you are looking for a high-quality writing service which can deal with all the writing problems - you can ask Essayslab https://essayslab.com/ for help
billiemichele · 15 weeks and 4 days ago
seo ]dsj juvdt seo search engine optimization ]dsj lukd seo seo shdj onlhj seo seokar newseo seo websima bartaramouz seo seoword.org seorooz.net seoyab.com seofox seofox.ir seolab.ir seo site ]dsj seo search engine optimization ]dsj search engine optimization seo website ]dsj seo definition ]dsj google seo ]dsj search optimization ]dsj shdj seo shdj search engine optimization seo ]dsj juvdt seo search engine optimization ]dsj lukd seo seo shdj onlhj seo seokar newseo seo websima bartaramouz seo seoword.org seorooz.net seoyab.com seofox seofox.ir seolab.ir seo site ]dsj seo search engine optimization ]dsj search engine optimization seo website ]dsj seo definition ]dsj google seo ]dsj search optimization ]dsj shdj seo shdj search engine optimization seo ]dsj juvdt seo search engine optimization ]dsj lukd seo seo shdj onlhj seo seokar newseo seo websima bartaramouz seo seoword.org seorooz.net seoyab.com seofox seofox.ir seolab.ir seo site ]dsj seo search engine optimization ]dsj search engine optimization seo website ]dsj seo definition ]dsj google seo ]dsj search optimization ]dsj shdj seo shdj search engine optimization seo ]dsj juvdt seo search engine optimization ]dsj lukd seo seo shdj onlhj seo seokar newseo seo websima bartaramouz seo seoword.org seorooz.net seoyab.com seofox seofox.ir seolab.ir seo site ]dsj seo search engine optimization ]dsj search engine optimization seo website ]dsj seo definition ]dsj google seo ]dsj search optimization ]dsj shdj seo shdj search engine optimization
seofox · 12 weeks and 3 days ago
Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization
seofox · 11 weeks and 6 days ago
Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization Search Engine Optimization
seofox · 11 weeks and 6 days ago
The commands really work. I had tested it. redding junk hauling
mark21 · 10 weeks and 2 days ago
I read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. Surge 365 Review
seomind · 9 weeks and 4 days ago
You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog. Surge 365 Review
seomind · 9 weeks and 4 days ago
The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought you have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention. scamrisk
seomind · 9 weeks and 4 days ago
Very informative post ! There is a lot of information here that can help any business get started with a successful social networking campaign ! scamrisk
seomind · 9 weeks and 4 days ago
I see the greatest contents on your blog and I extremely love reading them. Stealth Forex Trading System
seomind · 9 weeks and 4 days ago
Interesting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks Stealth Forex Trading System
seomind · 9 weeks and 4 days ago
I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! Stealth Forex Trading System
seomind · 9 weeks and 4 days ago
You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant! Stealth Forex Trading System
seomind · 9 weeks and 4 days ago
I need to to thank you for this very good read!! I definitely loved every little bit of it. I have you bookmarked to check out new things you post… Stealth Forex Trading System
seomind · 9 weeks and 4 days ago
If it's not too much trouble share more like that. scamrisk
seomind · 9 weeks and 4 days ago
Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir   Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir Seofox.ir
seofox · 9 weeks and 3 days ago
Online Marketing Bureau | SEO-SNEL: Digital Experts Online Marketing Bureau SEO-SNEL helpt bedrijven met het verbeteren van hun online zichtbaarheid door ? SEO ? Google Ads ? E-mail en ? Social in te zetten. SEO Specialist hypotheekrente Hypotheekrente overzicht | Rentevast | Hypotheekrentevast.nl Actuele hypotheekrentes van alle aanbieders. Rentevaste periode: hypotheekrente 10 jaar vast - 20 jaar vast - 30 jaar vast - Rentetarieven.
onlinemarketing · 8 weeks and 2 days ago
You delivered such an impressive piece to read, giving every subject enlightenment for us to gain information. Thanks for sharing such information with us due to which my several concepts have been cleared. https://toto808.com ???????
toto808 · 7 weeks ago
real estate web design read me more plez click link web design read me more plez click link web design read me more plez click link web design read me more plez click link web design read me more plez click link web design read me more plez click link web design
dewoweb · 5 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: