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

All commands from sorted by
Terminal - All commands - 11,605 results
openssl s_client -connect [host]:[sslport] -cipher LOW
2009-02-05 18:37:50
User: wwest4
6

...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
3

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
0

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
1

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
8

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
2

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
0

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
2

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
2

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
6

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
2

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
fsutil file createnew FILENAME filesize(inbytes)
2009-02-05 17:36:33
User: archlich
Functions: file
0

This command creates a file of arbitrary size in a windows environment.

ssh-keygen -i -f $sshkeysfile >> authorized_keys
PS1="\[\033[44;1;37m\]\u\[\033[0m\]@\h\\$ "
svn st | grep "^\?" | awk "{print \$2}" | xargs svn add $1
mount /path/to/file.iso /mnt/cdrom -oloop
2009-02-05 17:28:06
User: nerd65536
Functions: mount
Tags: mount iso
42

"-o loop" lets you use a file as a block device

gcc -Wall -Werror -o prog prog.c || rm -f prog.c
/bin/rpm -qf /etc/passwd /etc/issue /etc/httpd/conf/httpd.conf