Hide

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.

World cup college
Hide

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:

Hide

News

2010-03-03 - Commandlinefu @ SXSW 2010
Am going to be at SXSW this year, in case you want to submit any CLI nuggets or suggestions to me in person. Ping me on the @codeinthehole Twitter account.
2009-09-12 - Email updates now available
You can now enable email updates to let you know each time you're command is commented on.
2009-07-11 - API and javascript blog widget now available
A simple API has been released, allowing commands to be retrieved in various formats. This also allows commands to be embedded on blogs/homepages.
2009-05-17 - Added duplicate suggestions to the new command form
When adding a new command, a quick background search is performed to make sure you're not duplicating a command already in the system.
Hide

Tags

Hide

Functions

Run the last command as root

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

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

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives
pfexec !!
sudo !!
2009-02-25 00:52:28
User: silbermm
Functions: sudo
-3

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 55 weeks and 5 days ago

Doesn't this only work under ZSH ?

Comment by pyrho 55 weeks and 4 days ago

doesnt seem to work under bash/centos4?

Comment by trix 55 weeks and 3 days ago

work on Ubuntu 8.04

Comment by mrbyte 55 weeks and 3 days ago

works on fedora with bash!

Comment by betsubetsu 54 weeks and 6 days ago

I almost never use sudo. It promotes bad security: using the same password for root and and for regular users.

Comment by grep 54 weeks and 5 days 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 54 weeks and 1 day ago

works in bash/Debian !!

Comment by prayer 53 weeks and 4 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

Comment by Meeko 52 weeks 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/

Comment by mpb 51 weeks and 4 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)

Comment by bulwynkl 51 weeks 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 50 weeks and 6 days ago

The HOME key is a single key press.

Why chose a two key sequence instead of one?

Comment by mpb 50 weeks and 4 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...
Comment by isaacs 50 weeks and 1 day 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 49 weeks and 6 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 48 weeks and 2 days ago

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

Comment by kylexlau 43 weeks and 1 day ago

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

http://www.vanginderachter.be/2009/patched-xkcd-149-make-me-a-sandwich/

Comment by svg 39 weeks and 4 days ago

This is great!

Comment by marcop 24 weeks and 1 day ago

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

Comment by unixmonkey6345 24 weeks and 1 day ago

nice

Comment by haven489 6 weeks and 5 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts