What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Run the last command as root

Terminal - Run the last command as root
sudo !!
2009-01-26 10:26:48
User: root
Run the last command as root

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


There are 3 alternatives - vote for the best!

Terminal - Alternatives
2010-11-19 17:40:01
User: strzel_a

\$ which python


\$ ll `!!`

lrwxrwxrwx 1 root root 9 2010-11-08 22:01 /usr/bin/python -> python2.6

su -c "!!"
2012-02-21 15:38:30
User: mesuutt
Functions: su

Same as `sudo !!`. If you do not have permission to be sudo or sudo does not installed on your system, you can use this.

pfexec !!
sudo !-1
2013-04-22 03:45:14
User: datamining
Functions: sudo

this command also can run the last command as root

what's more, sudo !-2 can run the second last command as root , and so on

sudo !!
2009-02-25 00:52:28
User: silbermm
Functions: sudo

I often forget to type sudo before a command that needs it. This is the quickest way to rerun the command prefixed by sudo.

Know a better way?

If you can do better, submit your command here.

What others think

This one might be my most commonly used "one liner". I even wrote a post about it in my blog ;)

Comment by JackiesJungle 354 weeks and 1 day ago

Doesn't this only work under ZSH ?

Comment by pyrho 354 weeks ago

doesnt seem to work under bash/centos4?

Comment by trix 353 weeks and 6 days ago

work on Ubuntu 8.04

Comment by mrbyte 353 weeks and 6 days ago

works on fedora with bash!

Comment by betsubetsu 353 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.

Comment by grep 353 weeks and 1 day 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)
Comment by farglenargle 352 weeks and 4 days ago

works in bash/Debian !!

Comment by prayer 352 weeks 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

Comment by Meeko 350 weeks and 3 days ago

@meeko "All the way to the beginning"? Just hit the HOME key. Life is short! :-)

sudo is great for sandwich making also:


Comment by mpb 350 weeks 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



nslookup !$

will translate to


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)

Comment by bulwynkl 349 weeks and 3 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.

Comment by cmang 349 weeks and 2 days ago

The HOME key is a single key press.

Why chose a two key sequence instead of one?

Comment by mpb 349 weeks ago

I love this because it always feels like I'm yelling at my computer.

do_something # i don't wanna... SUDO!! # ok, fine...
Comment by isaacs 348 weeks and 4 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.

Comment by jxy 348 weeks and 2 days 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.

Comment by qubyte 346 weeks and 5 days ago

I use Ctrl+p, Ctrl+a, sudo before.

Comment by kylexlau 341 weeks and 4 days ago

OK, this inspired me to patch xkcd-149 :)


Comment by svg 337 weeks and 6 days ago

This is great!

Comment by marcop 322 weeks and 4 days ago

Should work under bash, but you may have it disabled (set -H or set -o histexpand to reenable)

Comment by unixmonkey6345 322 weeks and 4 days ago


Comment by haven489 305 weeks and 1 day ago

I wrote an article about this and other popular one-liners. See it here:


Comment by pkrumins 297 weeks and 4 days ago

pretty good

Comment by deargodzw 297 weeks and 4 days ago

Explained the next 10 top one-liners:


Comment by pkrumins 296 weeks and 5 days ago

Worky fine, OS X Snow Leopard 10.6.3.

Comment by hced 292 weeks and 5 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

Comment by jemptymethod 268 weeks ago

WTF ? This is the best command for everyone ?

Damn ubuntu lamers...

Comment by gormux 257 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.

Comment by Karunamon 208 weeks and 6 days ago


Comment by jldbasa 199 weeks ago

@jemptymethod me too

Comment by dfang 174 weeks ago

Works in OS X Mountain Lion 10.8.1

Comment by mainmethod 168 weeks and 4 days ago

this command trick and many like it are part of the history command.


man history

for more variants

if your shell does not have history it wont work

Comment by bulwynkl 161 weeks and 2 days ago

this command trick and many like it are part of the history command.


man history

for more variants

if your shell does not have history it wont work

Comment by bulwynkl 161 weeks and 2 days 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".

Comment by mpb 43 weeks and 4 days ago

Your point of view

You must be signed in to comment.