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,620 results
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.

find /path/to/dir -type f -mtime +[#] -exec rm -f {} \;
2009-02-05 19:24:13
User: wwest4
Functions: find rm

deletes logs not modified in over [#] days - modify to compress or move, as needed

perl -pi -e 's/THIS/THAT/g' fileglob*
2009-02-05 19:19:52
User: elofland
Functions: perl

changes THIS to THAT in all files matching fileglob* without using secondary files

dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64
2009-02-05 19:19:20
User: twopoint718
Functions: dd

Alternatively, if your password can contain a richer character set, try using 'uuencode' rather than base64.

dd if=/dev/urandom bs=16 count=1 2>/dev/null | uuencode -

Sample of that: '0:.CF\-@"\`W315VG^4O\.@``'

/usr/sbin/httpd -l
2009-02-05 19:06:43
User: Mattie

For some of my web servers I setup and configure, for scaling I use the httpd.conf settings for these. Sometimes I forget which servers are prefork and which are worker MPM, so I use this to remind myself.

dd if=/dev/zero bs=1024 count=1440 > floppy.img && mkdosfs floppy.img
2009-02-05 18:56:55
User: wwest4
Functions: dd mkdosfs

mount with:

mount -t msdos -o loop ./floppy.img /tmp/mnt

awk '{if (NR % 2 == 1) print $0}' file.txt
awk '{if (NR % 2 == 0) print $0}' file.txt
openssl s_client -connect [host]:[sslport] -cipher LOW
2009-02-05 18:37:50
User: wwest4

...if you get a certificate back, the server is accepting weak SSL ciphers

perl -e '$b="bork"; while(<STDIN>){$l=`$_ 2>&1`; $l=~s/[A-Za-z]+/$b/g; print "$l$b\@$b:\$ ";}'
2009-02-05 18:33:40
User: fonik
Functions: perl

Bork, bork, bork!

To keep it short, the first terminal line doesn't show a prompt.

curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
xrandr --output [youroutput] --rotate [right|left|normal] -d [yourdisplay]
2009-02-05 18:28:43
User: michelem

You need the RANDR support enable, to enable it with an ATI card run:

aticonfig --set-pcs-str="DDX,EnableRandr12,TRUE"

To show your available output run:

xrandr -q -d [yourdisplay]
sed -i.`date +%Y%m%d` -e 's/pattern/replace' [filename]
2009-02-05 18:20:54
User: wwest4
Functions: sed

Does an in situ search-replace but leaves a datestamped backup. A variation with more precision:

sed -i.`date +%Y%m%d%H%M%S 's/pattern/replace' [filename]

watch -n 1 'pstack 12345 | tac'
2009-02-05 18:17:00
User: mkc
Functions: watch

This command repeatedly gets the specified process' stack using pstack (which is an insanely clever and tiny wrapper for gdb) and displays it fullscreen. Since it updates every second, you rapidly get an idea of where your program is stuck or spending time.

The 'tac' is used to make the output grow down, which makes it less jumpy. If the output is too big for your screen, you can always leave the 'tac' off to see the inner calls. (Or, better yet--get a bigger screen.)

Caveats: Won't work with stripped binaries and probably not well with threads, but you don't want to strip your binaries or use threads anyway.

sed -i 's/OLD/NEW/g' FILE
2009-02-05 18:07:41
User: nanexcool
Functions: sed

Very quick way to change a word in a file. I use it all the time to change variable names in my PHP scripts (sed -i 's/$oldvar/$newvar/g' index.php)

echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search]
2009-02-05 18:07:23
User: wwest4
Functions: echo read sed

customizable context searches - if you know sed, this is a basis for more complex context control than grep --context offers

ps auxf
2009-02-05 18:07:16
User: systemj
Functions: ps

Shows a tree view of parent to child processes in the output of ps (linux). Similar output can be achieved with pstree (also linux) or ptree (Solaris).

netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c