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,997 results
ps ax | grep <processname> | grep -v grep | awk '{print $1}' | sudo xargs kill -9
dd if=/dev/zero of=/dev/hda
for i in `netstat -rn |grep lan |cut -c55-60 |sort |uniq`; do ifconfig $i; done
2010-01-28 17:35:20
User: Kaio
Functions: cut grep ifconfig sort

HP UX doesn't have a -a switch in the ifconfig command.

This line emulates the same result shown in Solaris, AIX or Linux

alias pfind='ps aux | grep '
$ lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=100003119823986&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
dd if=/dev/urandom of=/dev/somedisk
2012-01-24 09:13:15
User: joedhon
Functions: dd

Same game as #10096 . loop as many times as you like.

cat > /dev/null
2010-10-08 14:35:25
User: GouNiNi
Functions: cat

In exemple, screen can bind keys to switch between windows. I like to use Ctrl + Arrow to move left or right window. So I bind like this in .screenrc :

bindkey ^[OD prev # Ctl-left, prev window

bindkey ^[OC next # Ctl-right, next window

rpm -qf /lib/modules/*
2010-03-01 05:00:56
User: megacoder
Functions: rpm

Exploit that RPM database just sitting there, taking up space.

while read line; do echo $line; done <<< "$var"
2011-09-22 16:53:32
User: totti
Functions: echo read

Consider the following simple situation [ reading something using while and read ]

[See script 1 in sample output]


The variable var is assigned with "nullll" at first. Inside the while loop [piped while] it is assigned with "whillleeee". [Onlly 2 assignments stmts]. Outside the loop the last assigned value for "var" [and no variable] inside the while can't be accessed [Due to pipe, var is executed in a sub shell].

In these type of situation variables can be accessed by modifying as follows.

[See script 2 in sample output]


Vary helpful when reading a set of items, say file names, stored on a file [or variable] to an array an use it later.

Is there any other way 2 access variables inside and outside the loop ??

while true; do sleep 4 ; xdotool click 1 ; done
2011-09-23 09:23:02
User: rusino
Functions: sleep

Automation click every 4 second on a macro slot bar to world of warcraft for prospecting item

enable auto loot and create macro, put mouse over slot on the bar

/cast Prospecting

/use Elementium Ore

history -r
poweriso convert image.daa -o image.iso -ot iso
for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done
2009-03-09 15:42:13
User: haivu
Functions: sleep
Tags: Os X

Listen to different voices in the system--useful for picking the voice you like

find /dir/ -name *name*
2009-02-09 20:24:10
User: cinan
Functions: find

"*" is important if you don't know exact name of file. Check it out and you'll see

find . -exec chmod 777 {} \;
echo 00:29:36 | nawk -F: '{seconds=($1*60)*60; seconds=seconds+($2*60); seconds=seconds+$3; print seconds}'
pkill $1
2009-07-20 12:47:41
User: svg

There's already a proper command for what the former alternative tried to script

echo alias xkcd="gwenview `w3m -dump http://xkcd.com/|grep png | awk '{print $5}'` 2> /dev/null" >> .bashrc
2010-01-30 20:38:16
User: GinoMan2440
Functions: alias echo

Add an alias to your .bashrc that allows you to issue the command xkcd to view (with gwenview) the newest xkcd comic... I know there are thousands of them out there but this one is at least replete with installer and also uses a more concise syntax... plus, gwenview shows you the downloading progress as it downloads the comic and gives you a more full featured viewing experience.

can(){ shift 2; sudo "$@"; }
lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|grep -v ^$
2009-11-04 22:23:45
User: xeor
Functions: grep sed

For those of us that still uses lynx :)

TZ=GMT date -d "1970/01/01 00:29:36" +%s
print -l $path
2009-08-27 16:33:04
User: Mikachu
Tags: zsh PATH

This doesn't work in bash, but in zsh you can typeset -T to bind a scalar variable to an array. $PATH and $path behave this way by default.

date -ud "1970/01/01 00:29:36" +%s
2011-11-01 17:02:46
User: frans
Functions: date
Tags: echo date time

uses the -u switch for UTC

Another way could be

echo $(($(date -ud "00:29:36" +%s)%86400))
echo *
2009-04-17 21:40:58
User: kFiddle
Functions: echo
Tags: echo ls

Sometimes "ls" is just too slow, especially if you're having problems with terminal scroll speed, or if you're a speed freak. In these situations, do an echo * in the current directory to immediately see the directory listing. Do an echo * | tr ' ' '\n' if you want a column. Do an alias ls='echo *' if you want to achieve higher echelons of speed and wonder. Note that echo * is also useful on systems that are so low in memory that "ls" itself is failing - perhaps due to a memory leak that you're trying to debug.