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.

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

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

Tags

Hide

Functions

Inserts the results of an autocompletion in the command line

Terminal - Inserts the results of an autocompletion in the command line
ESC *
2009-06-14 21:17:40
User: Josay
57
Inserts the results of an autocompletion in the command line

Pressing ESC then * will insert in the command line the results of the autocompletion.

It's hard to explain but if you look the sample output or do

echo ESC *

you will understand quickly.

By the way, few reminders about ESC :

- Hold ESC does the same thing as tab tab

- 'ESC .' inserts the last argument of last command (can be done many times in order to get the last argument of all previous commands)

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives

Know a better way?

If you can do better, submit your command here.

What others think

interesting :)

<ESC> *

returns all the commands in a row.

<ALT><NUM><.>

grabs the 'NUM' argument from the previous command and puts it in the current command. 'NUM'=0 is the command

eg.

#ls a b c

--some output--

# #that is equal to 'ls b'

Comment by JesusSuperstar 253 weeks and 2 days ago

formating messed up the example above

eg:

ls a b c

--some output

<ALT><0><.> <ALT><2><.>

# is equal to 'ls b'

you have to holt the 'Alt' key the whole time.

Comment by JesusSuperstar 253 weeks and 2 days ago

Thanks a lot, that's awesome.

Comment by Josay 253 weeks and 2 days ago

I don't see in which case that's interesting. To make a for loop, simply remplace the command by "*" :

for i in *; do somethingWith $i; done
Comment by sputnick 253 weeks and 2 days ago

Sputnick > because it's inserted in your command line, you can add/remove/change elements easily.

And pressing 2 keys is faster than remembering the syntax for the for loop.

Comment by Josay 253 weeks and 2 days ago

Excellent!! Thanks for this.

Comment by DaveQB 253 weeks and 2 days ago

It also works with wildcard filtering:

echo *.ogg<ESC>* # List *.ogg files echo *w*<ESC>* # List filenames containing 'w'
Comment by sunny256 253 weeks and 1 day ago

Seems to not work on Fedora 8/Bash

Comment by ozymandias 253 weeks and 1 day ago

@ozymandias

What version of bash are you using? Mine is 3.2.39, and it works here.

Comment by sunny256 253 weeks and 1 day ago
bash --version

GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)

Comment by ozymandias 253 weeks and 1 day ago

Whoa. Nice. Works fine here, on a gentoo machine .. "GNU bash, version 4.0.17(2)-release (x86_64-pc-linux-gnu)"

Comment by Alanceil 253 weeks and 1 day ago

Not trying to be a hater, but stuff like this is why I use zsh. In zsh there is no mystery as to how this works, it just does.

echo *<TAB>

When I'm forced to use bash, I try and make it act like zsh so I can keep my sanity*. So far I've failed :)

*says the long time zsh user. But seriously, give it a shot...

Comment by claytron 253 weeks and 1 day ago

Under bash 3.2.39 I can get echo *.c to work but ls -l *.c does not. Am I doing something wrong?

Comment by bwoodacre 252 weeks and 6 days ago

Same version, same problem.

Works :

echo * esc-* any_other_command esc-* echo *.c esc-*

Does not work :

any_other_command *.c esc-*

I just can't understand.

Comment by Josay 252 weeks and 5 days ago
Alt *

Does the same; I find it easier to type.

Comment by polar 252 weeks and 5 days ago

Work fine on ksh@AIX server ; )

Comment by Oxyaxion 128 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts