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,588 results
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 root@

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.

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 admin@NOC.NBIRN.NET -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 admin@NOC.NBIRN.NET -q "ktadd -k /etc/krb5.keytab host/hostname"
sed '/./=' infile | sed '/^/N; s/\n/ /'
2009-12-10 16:24:56
User: glaudiston
Functions: sed

There's too many options to number,

My curiosity has forced me to make it using only sed.

Maybe useful... or not... :-S

curl -s -H "Authorization: GoogleLogin auth=$auth" "http://www.google.com/reader/api/0/unread-count?output=json" | tr '{' '\n' | sed 's/.*"count":\([0-9]*\),".*/\1/' | grep -E ^[0-9]+$ | tr '\n' '+' | sed 's/\(.*\)+/\1\n/' | bc
2010-02-11 00:42:57
User: matthewbauer
Functions: grep sed tr

Get Google Reader unread count from the command line.

You'll have to define your auth token with $auth

Or use:

curl -s -H "Authorization: GoogleLogin auth=$(curl -sd "Email=$email&Passwd=$password&service=reader" https://www.google.com/accounts/ClientLogin | grep Auth | sed 's/Auth=\(.*\)/\1/')" "http://www.google.com/reader/api/0/unread-count?output=json" | tr '{' '\n' | sed 's/.*"count":\([0-9]*\),".*/\1/' | grep -E ^[0-9]+$ | tr '\n' '+' | sed 's/\(.*\)+/\1\n/' | bc
head -c20 /dev/urandom | xxd -ps
2013-07-16 10:14:21
User: opexxx
Functions: head
Tags: HEAD urandom

20characters long alpahnumeric "password"

ssh -l <username> <server>
while [ 1 ]; do echo -e "220 ProFTPD 1.3.3c Server [ProFTPD] \nFAILED FTP ATTEMPT - PORT 21" | nc -vvv -l 21 >> /var/log/honeylog.log 2>> /var/log/honeylog.log; done
2013-07-16 19:05:37
User: xmuda
Functions: echo

[root@dhcppc1 windows]# cat /var/log/honeylog.log

Connection from port 21 [tcp/ftp] accepted

Connection from port 21 [tcp/ftp] accepted

[root@dhcppc1 windows]# nc 21

220 ProFTPD 1.3.3c Server [ProFTPD]


*You can not run it if you have activated the ftp server.

cleartool co -nc `cleartool ls -recurse | grep "hijacked" | sed s/\@\@.*// | xargs`
curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i 40 -d 30 -l 2
2009-11-12 21:33:06
User: m33600
Functions: awk grep

I have a custmer's Geovision DVR installed on a closed proxi (only logme-in reaches it).

I have to check for reliability but logmein hangs and is too slow a process

I made the Geovision software send e-mail every minute to the www.spam.la site.

All this script does is to retrieve the e-mail header from spam.la ( no login!), filtering sender, stopping at the first occurrence of the word "secs" ( the age of the last e-mail ).

The result is the age of the sender's last e-mail, tiny published on top of my screen once a minute.

I can refresh www.spam.la via web browser, but have other things to do.

I use it inside Kalarm ( kde task schedule ) set to 1 minute repeat.

It can be done without kalarm, using Watch outside the script.

Try it out now using my account = geo1 ( change sender by geo1 in this script)

Needs curl , osd-bin

echo $?
2011-07-27 15:34:20
User: lucasrangit
Functions: echo

I often find it useful to know what the exit status for a program was. This can be helpful when looking up errors by exit status or when scripting frequent commands.

Taken from http://www.faqs.org/docs/abs/HTML/exit-status.html

zenity --list --width 500 --height 500 --column 'Wallpapers' $(ls) | xargs xsetbg -center -smooth -fullscreen
2011-11-15 02:44:48
User: TheShadowFog
Functions: xargs

Assuming you have zenity installed, and assuming that you keep your backgrounds in ~/backgrounds, then this should work for you! :)