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

Commands by lucasrangit from sorted by
Terminal - Commands by lucasrangit - 9 results
gcc -dM -E - < /dev/null
sed '${LINE}d' ~/.ssh/known_host
2012-01-16 18:00:12
User: lucasrangit
Functions: sed
-5

When you SSH to a server who's hostname or IP has changed since the last time a connection was recorded in the known_hosts file a warning will be displayed since this indicated a possible DNS spoofing attack. If this is a known change then this command will remove the previous entry and allow the SSH connection. The SSH client will prompt you as if it was the first time connected to the server.

Replace ${LINE} with the line of the offending key in ~known_hosts. 49 in the sample output.

echo $?
2011-07-27 15:34:20
User: lucasrangit
Functions: echo
-1

I often find it useful to know what the exit status for a program was. This can be helpful when looking up errors by exit status or when scripting frequent commands.

Taken from http://www.faqs.org/docs/abs/HTML/exit-status.html

svn propset svn:executable ON filename
pdfimages -j foo.pdf bar
2011-07-07 17:18:36
User: lucasrangit
Tags: pdf jpeg
3

This will extract all DCT format images from foo.pdf and save them in JPEG format (option -j) to bar-000.jpg, bar-001.jpg, bar-002.jpg, etc.

Inspired by http://stefaanlippens.net/extract-images-from-pdf-documents

ssh vm-user@`VBoxManage guestproperty get "vm-name" "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $2 }'`
2011-05-04 18:01:36
User: lucasrangit
Functions: awk get ssh
9

Booting the VM headless via VBoxHeadless requires knowledge of the VM's network in order to connect. Using VBoxManage in this way and you can SSH to the VM without first looking up the current IP, which changes depending on how you have your VM configured.

awk '{printf("/* %02d */ %s\n", NR,$0)}' inputfile > outputfile
2011-01-04 19:13:55
User: lucasrangit
Functions: awk
1

I often find the need to number enumerations and other lists when programming. With this command, create a new file called 'inputfile' with the text you want to number. Paste the contents of 'outputfile' back into your source file and fix the tabbing if necessary. You can also change this to output hex numbering by changing the "%02d" to "%02x". If you need to start at 0 replace "NR" with "NR-1". I adapted this from http://osxdaily.com/2010/05/20/easily-add-line-numbers-to-a-text-file/.

find . -name '*.[c|h]pp' -o -name '*.[ch]' -type f
2010-03-11 01:22:06
User: lucasrangit
Functions: find
2

Find C/C++ source files and headers in the current directory.