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:



2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.




Place the argument of the most recent command on the shell

Terminal - Place the argument of the most recent command on the shell
'ALT+.' or '<ESC> .'
2009-03-20 11:36:04
User: atoponce
Place the argument of the most recent command on the shell

When typing out long arguments, such as:

cp file.txt /var/www/wp-content/uploads/2009/03/

You can put that argument on your command line by holding down the ALT key and pressing the period '.' or by pressing <ESC> then the period '.'. For example:

cd 'ALT+.'

would put '/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing 'ALT+.' to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.


There are 3 alternatives - vote for the best!

Terminal - Alternatives
<ESC> .
<ALT> .
<ALT>+<.> or <ALT>+<NUM>+<.> or <ALT>+<NUM>,<ALT>+<.>
2011-03-01 17:41:08
User: aikikode

After executing a command with multiple arguments like

cp ./temp/test.sh ~/prog/ifdown.sh

you can paste any argument of the previous command to the console, like

ls -l ALT+1+.

is equivalent to

ls -l ./temp/test.sh

ALT+0+. stands for command itself ('ls' in this case)

Simple ALT+. cycles through last arguments of previous commands.

<Esc> _
2011-03-07 10:06:46
User: homburg

This works if your terminal is in Vi mode


Know a better way?

If you can do better, submit your command here.

What others think

hmm, remarkably similar to:


Comment by mpb 314 weeks and 3 days ago

Doesn't seem to work for me, they both just re-input what I just typed -- from the same line.

Comment by ozymandias 314 weeks and 3 days ago

@mpb Except that I don't require the use of the shift modifier. Further, comments don't get as high attention as a newly submitted command.

@ozymandias If your previous command didn't have an argument, then it will just place the previous command on the line.

Comment by atoponce 314 weeks and 2 days ago

atoponce -- that's what I tested...

Comment by ozymandias 313 weeks and 2 days ago

Only 'ESC+.' works for me.

Comment by bwoodacre 308 weeks and 5 days ago

Make sure you're holding Alt while pressing period. If you press . again it will go back in history too. If only Esc . works for you, you need to set your terminal to send meta as escape.

Comment by rkulla 258 weeks and 5 days ago

Only Escape + . works for me in Terminal on a Mac.

Comment by erikhansen 255 weeks and 3 days ago

In Vi mode:

<Esc> _

Or to choose arg and _ to activate:

<Alt>+<num>, _
Comment by homburg 212 weeks ago

You can also use the numeric prefix to adjust the argument from the previous command which will be used.

In bash, the numeric prefix is Esc (\e below) followed by any number of digits, and the modifier counts parameters from the start, with \e0\e. giving you the command itself, \e2\e. the second parameter.

In zsh, the numeric prefix is extended by \e single-digit, so to pass in 12 it's \e1\e2. For \e. zsh counts backwards with 1 being the *last* parameter, so that \e. and \e1\e. are equivalent. This makes sense, since the numeric prefix is conceptually a repetition count. Except that zsh then makes \e0\. get the command position, same as bash.

Still both useful. Add in on zsh:

zle -N copy-earlier-word bindkey '^[,' copy-earlier-word

and you have \e, to copy the previous word from the *current* command-line, and numeric prefices upon that, and the ability to mess around with long paths gets much easier.

Comment by syscomet 149 weeks and 1 day ago

You can also use $_ in BASH. Good for scripts. :)

Comment by somaddict 123 weeks and 3 days ago

works on my machine, running Gnome 2 on Debian.

Comment by sandcurves 119 weeks and 1 day ago

Ok, pressing . gives me older and older commands, but what if I go too far, ans would like to cycle forward?

Comment by unixmonkey63146 86 weeks and 4 days ago

Can anyone help with the Vi-mode version

<Esc> _

doesn't seem to work for me.

Comment by crashandburn4 54 weeks and 3 days ago

the ALT "." command has become one of the biggest time savers I've ever used w/the added benifit of a little less risk than using some other similar options. This, and `sudo !!` have saved me lots of time. But "." is the cats meow.

Comment by substdio 52 weeks and 1 day ago

Your point of view

You must be signed in to comment.