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





All commands from sorted by
Terminal - All commands - 12,230 results
cat dump.sql | sed -n -e '/Table structure for table .table1./,/Table structure for table .table2./p'
2012-11-22 23:54:04
User: infojunkie
Functions: cat sed
Tags: mysql sed

Given a dump.sql file, extract table1 creation and data commands. table2 is the one following table1 in the dump file. You can also use the same idea to extract several consecutive tables.

awk 'BEGIN{ORS=""}NR!=1&&FNR==1{print "\n"}{print}END{print "\n"}' *.txt
2010-05-24 19:22:35
User: recursiverse
Functions: awk

Problem: you want to output one line per file. you can't just 'tr -d' because you want one line per file and you don't want to use a loop.

Solution: use awk to print each line without the record separator and a newline after each file.

source <(egrep '^#define EX_.*' /usr/include/sysexits.h | sed -e 's/#define/declare -r/g' | sed 's/\//#/g' | sed -e 's/\s\{1,\}/ /g' | sed -e 's/ \([0-9]\)/\=\1/'g )
2012-09-21 13:30:37
User: fishdaemon
Functions: egrep sed

Use meaningful exit codes

change "source" to "cat" to view output instead of assigning

plink lyu0@mysshserver -pw 123456
gst-launch v4l2src
2009-03-23 05:45:00
User: samliu

Cheese or other webcam software not working? Try this.

dpkg -l |grep i386 | awk '{ print "apt-get -y remove --purge "$2 }' | sh
(echo -e '\x06\x00\x00\x00\x00\x00\x01\x01\x00'; sleep 1)|nc -c $host 25565
ls | grep -vi pattern
scselect <location>
2011-01-26 03:56:14
User: gwchamb

Use this command to change your network location from the OSX command line.

sudo rpm -if "http://rpm_server/rpm_repo/this-app.rpm"
strings -1 <file>
2012-11-23 11:33:25
User: Testuser_01
Functions: strings

Use this like the cat command with the additional feature to strip out unprintable characters from the input, newlines will stay.

find . -maxdepth 1 -type f| xargs sha1sum | sed 's/^\(\w*\)\s*\(.*\)/\2 \1/' | while read LINE; do mv $LINE; done
gnome-open .
2010-10-01 13:16:00
User: pahnin

when working under a cli sometime you need to list the files with ls

but u can open gnome file browser with the command 'gnome-open .' under current directory

curl -D - -X POST -H 'Content-type: text/xml' -d @XML http://remote_server:8080/web-service/soap/WSName
2011-05-23 08:25:24
User: igorfu

Use curl to invoke remote web service, where the file 'XML' is the soap payload

cd !$
2010-08-26 08:51:01
User: YCFlame
Functions: cd

using "!$" will save another ton of typing than 'ALT+.' or ' .'

2011-05-23 08:27:22
User: igorfu
Tags: vi

French uses accents (???...) which may be badly displayed on computers with the wrong default character set. This command may help (sometimes)

sudo nano /etc/modules-load.d/virtualbox.conf
2013-05-16 14:41:51
Functions: sudo

To do this, we?ll use nano to create a new configuration file called ?virtualbox.conf?. This file will go in the ?/etc/modules-load.d? directory, which contains files that need to be loaded when Arch boots up. Since adding a file to this directory requires administrative permissions, we?ll need to precede our command with ?sudo? once again.

When nano brings up the blank file, add these three lines to it:




As usual, when you?re finished entering text in nano, type Control-X to exit to the command line, and answer ?y? for yes when you?re asked whether you want to save your work, and then hit ?Return? to accept the filename. At this point, reboot your machine for the Guest Additions to take effect.

git ls-files | while read i; do git blame $i | sed -e 's/^[^(]*(//' -e 's/^\([^[:digit:]]*\)[[:space:]]\+[[:digit:]].*/\1/'; done | sort | uniq -ic | sort -nr
2009-10-25 09:40:01
User: pipping
Functions: read sed sort uniq
Tags: statistics git

You'll run into trouble if you have files w/ missing newlines at the end. I tried to use

PAGER='sed \$q' git blame

and even

PAGER='sed \$q' git -p blame

to force a newline at the end, but as soon as the output is redirected, git seems to ignore the pager.

git grep "search for something" $(git log -g --pretty=format:%h -S"search for something")
M=bob@example.com; echo "Email message" | mutt -s "Email Subject" $M
2011-05-23 08:31:14
User: igorfu
Functions: echo
Tags: email

It's very similar to this thread:


mutt your@email_address.com -s "Message Subject Here" -a attachment.jpg </dev/null
eval <command> ${INBACK:-&}
2012-04-05 03:50:57
User: Zulu
Functions: eval
Tags: bash eval nohup

If $INBACK is set, command will launch in foreground and inverse.

Very useful in script !

We could apply the inverse comportement like that :

eval command ${INBACK:+&}

sudo reboot
dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
2013-10-23 15:53:27
User: scotharkins
Functions: dd

This example is taken from Cygwin running on Win7Ent-64. Device names will vary by platform.

Both commands resulted in identical files per the output of md5sum, and ran in the same time down to the second (2m45s), less than 100ms apart. I timed the commands with 'time', which added before 'dd' or 'readom' gives execution times after the command completes. See 'man time' for more info...it can be found on any Unix or Linux newer than 1973. Yeah, that means everywhere.

readom is supposed to guarantee good reads, and does support flags for bypassing bad blocks where dd will either fail or hang.

readom's verbosity gave more interesting output than dd.

On Cygwin, my attempt with 'readom' from the first answer actually ended up reading my hard drive. Both attempts got to 5GB before I killed them, seeing as that is past any CD or standard DVD.


'bs=1M' says "read 1MB into RAM from source, then write that 1MB to output. I also tested 10MB, which shaved the time down to 2m42s.

'if=/dev/scd0' selects Cygwin's representation of the first CD-ROM drive.

'of=./filename.iso' simply means "create filename.iso in the current directory."


'-v' says "be a little noisy (verbose)." The man page implies more verbosity with more 'v's, e.g. -vvv.

dev='D:' in Cygwin explicitly specifies the D-drive. I tried other entries, like '/dev/scd0' and '2,0', but both read from my hard drive instead of the CD-ROM. I imagine my LUN-foo (2,0) was off for my system, but on Cygwin 'D:' sort of "cut to the chase" and did the job.

f='./filename.iso' specifies the output file.

speed=2 simply sets the speed at which the CD is read. I also tried 4, which ran the exact same 2m45s.

retries=8 simply means try reading a block up to 8 times before giving up. This is useful for damaged media (scratches, glue lines, etc.), allowing you to automatically "get everything that can be copied" so you at least have most of the data.

iptables -A INPUT -s -j DROP
ls -trF | grep -v \/ | tail -n 1
2011-09-14 20:05:37
User: mrpollo
Functions: grep ls tail
Tags: find stat mtime

Sort by time and Reverse to get Ascending order, then display a marker next to the a file, negate directory and select only 1 result