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
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
for x in */*.rar; do unrar x $x; done
2009-02-05 18:01:58
User: sheptard

Grabs all rar files in any current subdirectories and feeds it to unrar. Doesn't work well with things packaged like file.part01.rar. Works best with File.rar. You can recurse into other directories by adding more /*'s

mysqldump --where="true LIMIT X" databasename > output.sql
egrep -ie "<*HREF=(.*?)>" index.html | awk -F\" '{print $2}' | grep ://
for i in `ps aux | grep httpd | awk '{print $2}'`; do lsof -n -p $i | grep ESTABLISHED; done;
2009-02-05 17:50:52
User: Shadow
Functions: awk grep

Sometimes apache will get stuck in an established state where you can't get a list of the connecting IP's from mod_status... not a good thing when you need to ban an abusive ip.

find . -type d -name '.svn' -print0 | xargs -0 rm -rdf
ssh-keygen -l -f [pubkey] | awk '{print $2}' | tr -ds ':' '' | egrep -ie "[a-f0-9]{32}"
tcpdump -nli eth0; tcpdump -nli eth0 src or dst w.x.y.z; tcpdump -nli eth0 port 80; tcpdump -nli eth0 proto udp
2009-02-05 17:41:55
User: jonty
Functions: tcpdump

At some point you want to know what packets are flowing on your network. Use tcpdump for this. The man page is obtuse, to say the least, so here are some simple commands to get you started.

-n means show IP numbers and don't try to translate them to names.

-l means write a line as soon as it is ready.

-i eth0 means trace the packets flowing through the first ethernet interface.

src or dst w.x.y.z traces only packets going to or from IP address w.x.y.z.

port 80 traces only packets for HTTP.

proto udp traces only packets for UDP protocol.

Once you are happy with each option combine them with 'and' 'or' 'not' to get the effects you want.

find . -name "*.py" | xargs wc -l