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.

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.

Universal configuration monitoring and system of record for IT.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,378 results
curl -s "http://www.google.com/ig/api?weather=New%20York" | sed 's|.*<temp_f data="\([^"]*\)"/>.*|\1|'
2010-02-08 23:06:48
User: matthewbauer
Functions: sed

Will return temperature in Fahrenheit of a location (New York City in example).

Uses a Google API.

cat 1.tar.gz 2.tar.gz | tar zxvif -
2010-05-09 03:50:00
Functions: cat tar

You don't need to create an intermediate file, just pipe the output directly to tar command and use stin as file (put a dash after the f flag).

function titlescroll { _X=0 _TITLEMSG=$1 _WIDTH=${2:-16} _TITLEMSG=`printf "%$((${#_TITLEMSG}+$_WIDTH))s" "$_TITLEMSG"` while `true` do _X=$(((_X+1)%${#_TITLEMSG})) xtitle "${_TITLEMSG:_X:_WIDTH}" done }
2010-01-12 20:48:46
User: romulusnr


titlescroll "message" <width>

Requires command "xtitle" or replace with:

echo -ne "\e]0;TEXT_HERE\007"
find ./ -name Thumbs.db -exec rm -rf '{}' +
expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024
> filename
locate -i yourfilename | sed 's/ /\\ /g' | xargs ls -lah | less
mformat -f 1440 A:
2009-12-10 06:51:20
User: eastwind
Functions: mformat

The 1440 is the number of bytes, and the A: specifies the floppy drive.

find /lib/modules/`uname -r`/ -type f -iname '*.o' -or -iname '*.ko' |grep -i -o '[a-z0-9]*[-|_]*[0-9a-z]*\.ko$' |xargs -I {} echo '# {}' >>/etc/modules.autoload.d/kernel-2.6
2010-01-13 02:12:08
User: paragao
Functions: echo find grep xargs

Whenever you compile a new kernel, there are always new modules. The best way to make sure you have the correct modules loaded when you boot is to add all your modules in the modules.autoload file (they will be commented) and uncomment all those modules you need.

Also a good way to keep track of the available modules in your system.

For other distros you may have to change the name of the file to /etc/modprobe.conf

sshmysql() { ssh -L 13306: -N $* & }
2011-09-01 10:21:55
Functions: ssh

Create a secure tunnelled connection for access to a remote MySQL database.

For example, connect with MySQL Workbench to [email protected]:13306.

locale | grep LANG=
goyoutube() { d=/path/to/videos p=$d/playlist m=$d/*.mp4 f=$d/*.flv if [ "$1" == 'rand' ]; then ls -1 $m $f | shuf >$p else ls -1t $m $f >$p fi mplayer -geometry 500x400 -playlist $p }
2010-04-11 18:53:49
User: meathive
Functions: ls

newly downloaded videos



goyoutube rand

This command assumes you've already downloaded some YouTube .mp4 or .flv video files via other means. Requires 'shuf', or your own stdin shuffler.

who am i | wc -l
less file.tar.gz
2009-03-15 23:00:05
User: allbad
Functions: less

This will print out the files and directories in a gzipped tarball.

netstat -nut | awk '$NF=="ESTABLISHED" {print $5}' | cut -d: -f1 | sort -u
2011-07-27 07:24:10
User: bitbasher
Functions: awk cut netstat sort

find all computer connected to my host through TCP connection

find -regextype posix-egrep -regex ".*/[A-Z]{3}_201009[0-9]{2}.*" -printf "%f %s\n" | awk '{ SUM += $2;COUNT++ } END { print SUM/1024 " kb in " COUNT " files" }'
(cd /Applications/Firefox.app/Contents/MacOS; ./firefox-bin -p default --no-remote)
killall -s 9 krunner_lock
2009-05-21 22:29:06
User: b2e
Functions: killall

With this you can unlock your KDE4 session via SSH, via mobile phone SSH or e. g. scheduled task in crontab (without asking password). Useful when you need to grant somebody access to your locked profile remotely.

Create an alias (e. g. as "unlock") and use with remote KDE4 lock.

This works only on KDE4 boxes because KDE 3 is using utility with another name.

Tested on Kubuntu 8.10.

(echo "plot '-' with lines"; for x in $(seq 1 100); do curl -s "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=$(echo $x bottles of beer on the wall|sed 's/ /%20/g')"|sed 's/.*"estimatedResultCount":"\([^"]*\)".*/\1\n/';done)|gnuplot -persist
2010-03-17 21:04:36
User: matthewbauer
Functions: echo sed seq

Will create a graph of the results for "x bottles of beer on the wall".

Requires Gnuplot.

Inspired by an xkcd comic: http://xkcd.com/715/

For sample output see: http://tr.im/xbottlesofbeer

chmod -R u=rw-x+X,g=r-x+X,o= .
2010-07-16 18:42:00
User: donnoman
Functions: chmod
Tags: bash Ubuntu

forces user to rw, group to r, and other to no access.

files will not be marked executable.

directories will be executable for users and groups only.

grabtweets() { curl -s -o $GT_TMP twitter.com/$1 | cat $GT_TMP | grep entry-content | sed -e :loop -e 's/<[^>]*>//g;/</N;//bloop' | sed 's/^[ \t]*//'; }
kadmin -p [email protected] -q "addprinc -randkey host/host"
ls -l $(find ./ -type l | perl -ne 'chomp; if (-d) { print "$_\n" }')
2010-07-16 19:31:28
User: rwadkins
Functions: find ls perl

This will list all symlinks that are directories under the current directory. This will help you distinguish them from regular files.

kadmin -p [email protected] -q "ktadd -k /etc/krb5.keytab host/hostname"