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,591 results
chgrp -R [projgroup] ; find /path/to/dir -type d -exec chmod g+s {} \;
2009-02-05 16:49:24
User: wwest4
Functions: chgrp chmod find

changes group ownership of all files/dirs in /path/to/dir to a project group [projgroup] and then gives the sgid bit to directories in that tree - all subsequently created files will inherit [projgroup]'s gid.

find /path/to/dir -user root -exec chown [nonprivuser] {} \;
2009-02-05 16:42:14
User: wwest4
Functions: chown find

useful if you want to start running a svc as a non-privileged user instead of root.

C:\WINDOWS\system32\cmd.exe /t:0A /k cd /d
du -sh *
2009-02-05 16:39:14
User: larsr
Functions: du

Use this as a quick and simple alternative to the slightly verbose "du -s --max-depth=1"

units "2048 bytes" "kibibytes"
2009-02-05 16:36:25
User: archlich

Easily convert units of similar measurement. May also be invoked alone, units.

for x in `git status | grep deleted | awk '{print $3}'`; do git rm $x; done
pidof httpd
find . -regex ".*\.[cChH]\(pp\)?" -print | etags -
2009-02-05 16:27:26
User: chidarste
Functions: etags find

The regular expression matches patterns of .c, .cpp, .C, .Cpp, .h, .hpp, .H, .Hpp. The matched files are piped through etags to create a TAGS file, useful for emacs. Alternate regex (if you aren't worried about capital .Cpp) is -regex ".*\.c\|.*\.cpp\|.*\.h"

pathrm() { PATH=`echo $PATH | sed -e "s=^${1}:==;s=:${1}$==;s=:${1}:=:="`; }
2009-02-05 16:25:12
User: wam
Functions: sed

Function to remove a specified path from your PATH environment variable.

pkill -f foo
2009-02-05 16:12:53
User: archlich

Be careful when issuing this command, it may kill unwanted processes!

To only search on the process name don't use the argument -f, pkill foo

ps -ef | grep APP | awk '/grep/!{print$2}' | xargs -i kill {}
2009-02-05 16:10:05
User: hooobs
Functions: awk grep kill ps xargs

Probably posted previously, I use this all the time to find and kill a process for "APP". Simply replace "APP" with the name of the process you're looking to kill.

rpm -qa --last
2009-02-05 16:00:56
User: systemj
Functions: rpm

the newest rpms are at the top; individual packages can also be queried this way:

rpm --last -q package

vimdiff tera.py <(ssh -A testserver "cat tera.py")
alias pi='`cat ~/.pi | grep ' ; alias addpi='echo "cd `pwd`" >> ~/.pi'
2009-02-05 15:46:59
User: senthil
Functions: alias grep



user@ubuntu:~/workspace/SVN/haystak-repos/trunk/internal/src$ addpi


Now that directory is in the list of fast access directories.

You can switch to it anytime like this:


user@ubuntu:~$ pi internal`

user@ubuntu:~/workspace/SVN/haystak-repos/trunk/internal/src$ --------------------------------------------------------------------------------------------

Please note the backquote ( the symbol that shares its key with ~ in the keyboard )

pi will switch you to that directory.

To see the list of all fast access directories you have to say "cat ~/.pi"

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
2009-02-05 15:43:43
User: anokneemouse
Functions: python

Want to show something on your machine to someone over the web? Don't copy it or upload it somewhere. Just run "webshare" and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.

Found at www.shell-fu.org/lister.php?id=54

ps -e | grep SearchStringHere
lsof -i -n | grep ESTABLISHED
2009-02-05 15:28:11
User: systemj
Functions: grep

Uses lsof to list open network connections (file descriptors), grepping for only those in an established state

perl -pi -e 's/localhost/replacementhost/g' *.php
echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
2009-02-05 15:21:50
User: systemj
Functions: echo

remotely connects to an https site, fetches the ssl certificate and displays the valid dates for the cert

NAME=$(nslookup $IP | sed -n 's/.*arpa.*name = \(.*\)/\1/p'); test -z "$NAME" && NAME="NO_NAME"; echo "$NAME"
for i in *.bak ; do nuname=`echo $i | sed 's/\.[^\.]*$//'`; echo renaming $i to $nuname;mv $i $nuname; done
awk '/pattern1/ && /pattern2/ && !/pattern3/ {print}'
2009-02-05 15:18:19
User: themensch
Functions: awk

Rather than chain a string of greps together and pipe them to awk, use awk to do all the work. In the above example, a string would be output to stdout if it matched pattern1 AND pattern2, but NOT pattern3.

for i in * ; do cp $i $i.bak; done
2009-02-05 15:15:40
User: swinz
Functions: cp

quick in directory backup of all files in this directory. Adds the .bak extension to all copies.

ps -ef | grep $USER
2009-02-05 14:57:39
User: ryodoan
Functions: grep ps

I like to make it an alias in my .bashrc file, as such:

alias psme='ps -ef | grep $USER'

mysql -u uname dbname -e "show tables" | grep -v Tables_in | grep -v "+" | gawk '{print "optimize table " $1 ";"}' | mysql -u uname dbname