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.


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.




All commands from sorted by
Terminal - All commands - 11,587 results
myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
2009-02-05 22:13:43
User: stuart
Functions: echo sleep

This will ring the system bell once if your script exits successfully and twice if it fails. So you can go look at something else and it will alert you when done. Don't forget to use 'xset b [vol [pitch [duration]]]' to get the bell to sound the way you want.

pkill -U MYWIFE
2009-02-05 22:10:07
User: HansReiser

Kills all processes owned by user MYWIFE (replace MYWIFE with username or ID of your choice)

(Thanks, porges, for the better command)

tr -dc '[:print:]' < /dev/urandom
2009-02-05 21:51:14
User: gracenotes
Functions: tr

Reads psuedorandom bytes from /dev/urandom, filtering out non-printable ones. Other character classes can be used, such as [:alpha:], [:digit:] and [:alnum:]. To get a string of 10 lowercase letters:

tr -dc '[:lower:]' < /dev/urandom | head -c 10
2009-02-05 21:37:46
User: zgomot

Type ^u at password prompt to clear a mistyped password.

(on destination machine) nc -l 1234 > whatever; (on source machine) nc destination 1234 < whatever;
2009-02-05 21:35:08
User: jonty

Einstein's razor: As simple as possible, but not simpler.

On the destination machine netcat listens on any port (1234 in the example) and sends anything it receives into a file or pipe. On the source machine a separate netcat takes input from a file or pipe and sends it over the network to the listener.

This is great between machines on a LAN where you don't care about authentication, encryption, or compression and I would recommend it for being simpler than anything else in this situation. Over the internet you should use something with better security.

dig foo.org mx +short
cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
jstat -gc [jvmpid]
tidy -xml -i -m [file]
2009-02-05 21:22:33
User: scw

Generated XML files often are poorly formatted. Use this command to properly indent and normalize the file in-place.

cvs -Q status | grep -i locally
dos2unix dostxt unixtxt
2009-02-05 21:11:43
User: wwest4

converts non-ISO dos text files for use on unix systems.

touch -acm yyyymmddhhMM.ss [file]
2009-02-05 21:07:09
User: wwest4
Functions: touch

...changes modify time and access time. also:

touch -r [file1] [file2] # make file2 timestamp match file1

tar cfvz - /home/user | netcat -l -p 10000
2009-02-05 21:05:40
User: ajrobinson
Functions: tar

tar's directory and sends to netcat listening on port 10000

On the client end:

netcat [server ip] 10000 | tar xfvz -

This will send it over the network and extract it on the clients machine.

ldconfig -p
2009-02-05 21:02:59
User: wwest4
Functions: ldconfig

shows which shared lib files are pointed to by the dynamic linker.

echo "import random; print(random.choice(['heads', 'tails']))" | python
export SSH_AUTH_SOCK=`find /tmp/ssh* -type s -user [user] -mtime -1 | head -1`
2009-02-05 20:55:41
User: wwest4
Functions: export head

Must be done as root - will cause subsequent ssh connections to use the identities available via the [user]'s agent socket.

xxd < orig | sed 's/A/B/' | sed 's/HEXA/HEXB/' | xxd -r > new
2009-02-05 20:25:04
User: wwest4
Functions: sed

Replaces A with B in binary file "orig" and saves the result to "new". You must have the hex representations of A & B. Try od: echo -e "A\c" | od -An -x

sshfs name@server:/path/to/folder /path/to/mount/point
2009-02-05 20:17:41
User: ihasn

Install SSHFS from http://fuse.sourceforge.net/sshfs.html

Will allow you to mount a folder security over a network.

fuser -k filename
2009-02-05 20:16:11
User: fzero
Functions: fuser

Useful when you're trying to unmount a volume and other sticky situations where a rogue process is annoying the hell out of you.

convert pagexxx.png -filter Cubic -resize 200% -threshold 50% -compress Group4 pagexxx.tiff; tiff2pdf -z -p letter -ro -x 1200 -y 1200 -o pagexxx.pdf pagexxx.tiff
2009-02-05 20:14:06
User: Boojum

Scan pages in, clean them up in an image editor, save to individual files. Use this command to convert each page to PDF. Combine in Acrobat Professional, and use the built-in OCR with the "Searchable Image (Exact)" option. Gives excellent image quality and file size (avoids awful JPEG image recompression that Acrobat and other OCR systems tend to do.)

gs -dNOCACHE -dNOPAUSE -dBATCH -dSAFER -sDEVICE=epswrite -dEPSCrop -sOutputFile=out.eps in.pdf
2009-02-05 20:06:40
User: Boojum
Functions: gs

Use this to turn a page with snippets of equations into vector paths that Adobe Illustrator can handle without choking on font embedding and substitution issues. Good for keeping fonts consistent when labeling charts and diagrams. Also good for embedding formulas into diagrams.

echo -n "search> ";read QUERY && wget -O - `wget -O - -U "Mozilla/5.0" "http://images.google.com/images?q=${QUERY}" 2>/dev/null |sed -e 's/","http/\n","http/g' |awk -F \" '{print $3}' |grep -i http: |head -1` > "$QUERY"
2009-02-05 19:50:53
User: wwest4
Functions: echo wget

prompts for a search term and then pulls down the first result from google images

cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
2009-02-05 19:37:56
User: DEinspanjer
Functions: cat ssh

If you use Mac OS X or some other *nix variant that doesn't come with ssh-copy-id, this one-liner will allow you to add your public key to a remote machine so you can subsequently ssh to that machine without a password.

rpm --query --filesbypackage [packagename]
find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned"
2009-02-05 19:33:43
User: wwest4
Functions: find grep rpm sort

shows all RPMs with files in the current directory & its subdirectories.