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,605 results
ls | sed 's/.*/"&"/'
2010-08-17 15:38:51
User: putnamhill
Functions: ls sed
Tags: sed ls

Looks like you're stuck with sed if your ls doesn't have a -Q option.

dd bs=1 count=32 if=/dev/random 2> /dev/null | md5 | grep -o '\w*'
2009-02-26 12:52:45
User: alexfoo

Might match "ping" and then run it.

echo ?ls -l? | at 10am Jul 21
echo ?ls -l? | at midnight
curl -u user:pass -d status=?I am Tweeting from the shell? http://twitter.com/statuses/update.xml
2013-04-29 10:12:43
User: techie

Now all you have to do is replace user by your twitter username , pass by your password and the text inside status to whatever you wish to set your status too .

It uses cUrl library to post your messsage

sudo alsa force-reload
2009-02-16 03:30:13
User: oreo
Functions: sudo

if you lose your sound, this will restart alsa and you will get your sound back

oumou sangare
crontab -e
lynx -useragent=Opera -dump 'http://www.facebook.com/ajax/typeahead_friends.php?u=4&__a=1' |gawk -F'\"t\":\"' -v RS='\",' 'RT{print $NF}' |grep -v '\"n\":\"' |cut -d, -f2
_ff(){ cd /mnt;echo /mnt/*/* |sed 's/ \/mnt\//\&/g' |sed '/'"$1"'/!d'; cd -;}
2011-12-30 23:25:31
User: argv
Functions: cd echo sed


cd /mnt;

echo /mnt/*/* |sed '

s/ \/mnt\//\&/g;

'|sed '/'"$1"'/!d';

cd -;



case $# in


echo "usage: ff glob [sed-cmds] [--|var-name]"



_ff $1 |sed =



case $2 in

--) _ff $1 |less -SN


*) _ff $1 |sed -n ''"$2"''|tr '\n' '\040' |sed 's/.*/export '"$3"'=\"&/;s/=\" /=\"/;s/ $/\"/' > $HOME/.ff;

case $# in


. $HOME/.ff



sed '

s/export .*=\"/\$'"$3"' = \"/;' $HOME/.ff;\







local a=$HOME;

sed '

s/export /less -n \$/;


' $a/.ff > $a/.v ;

. $a/.v ;


Another approach using ls(1)


_lsl ()


ls -l $3 /mnt/*/$1* 2>/dev/null;


case $# in


echo "usage: lsl pat [ls-options|result-no]";

echo "usage: lsle pat [sed-cmds]"



_lsl $1 |sed =



case $2 in

-*) _lsl $1 $@;;


_lsl $1 |sed 's/.* //;


'"$2"'q' > $HOME/.lsl ;

export v=$(sed 1q $HOME/.lsl);

echo \$v = $v







echo "%s/\$/ /";

echo "%j";

echo "s/^/export v=\"";

echo "s/\$/\"";

echo "s/ \"\$/\"";

echo ".";

echo "wq";



lsl $1 -1 |sed $2 > .lsl&&

exp |ed -s .lsl >&-&&

. .lsl&&

echo \$v = $v;


2009-03-18 00:03:42
User: Zenexer
Functions: top

A simple but effective replacement for ps aux. I used to waste my time running ps over and over; top is the way to go. It also allows complex sorting options. Press q to exit "nicely" (Ctrl + C is always an option, of course). Note that the list updates each second, resorting in the process; if you're trying to grab a specific PID, you might be better off with ps.


Alternatively, htop is available, though it may not come pre-installed. htop is slightly more interactive than top and includes color coding, visuals, and a nice interface for selecting and then killing processes. (Thanks to bwoodacre for this great tool.)

kill -9 `pgrep $PROCESS_NAME`
2010-06-18 20:43:24
User: juanse006
Functions: kill

The pgrep retrieves the PID, then the KILL receive it, and kill it...

It works also if the application has more than one instance....

kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
2009-05-26 20:39:56
User: P17

Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.

dpkg-query -W | grep perl
2010-07-20 16:14:04
Functions: grep

IMVHO if you are using cpan to install perl modules you are doing it wrong.

FOR /f %%g in ('echo %1 ^| iconv -f gbk -t utf-8') DO curl -x proxy:port -u user:pass -d status=%%g -d source="cURL" http://twitter.com/statuses/update.xml
2010-07-21 04:53:54
User: MeaCulpa
Functions: iconv

Aside from curl one will need iconv windows binary since windows lacks a native utf-8 cli interface. In my case I need a proxy in China and iconv to convert gbk status string into utf-8. GnuWin32 is a good choice with loads of coreutils natively ported to Windows

"FOR /f" is the solution to pass iconv output to curl.

Printing portion of a big file
2009-03-30 11:08:38
User: acirulli
Tags: sed

If you need to print some portion of a huge file, let's say you want to print from line 200 to 300, you can use this command to print the line from LINE1 to LINE2 of file FILE.

shred -v filename
dd if=/dev/urandom of=/dev/speaker bs=1
2010-10-27 09:22:40
User: khashmeshab
Functions: dd

Sends random beeps to your PC-speaker. Think... You can also run it remotely on another computer using SSH and scare its user! Don't forget to run it on your dedicated hosting server and watch sysadmin's action from data-center's live remote cameras!

awk 'END {print NR}' /etc/passwd
dd if=/dev/urandom of=/dev/dsp
2010-10-27 09:25:02
User: khashmeshab
Functions: dd

Sends random sounds to your sound card output (e.g. your speaker). Think... You can also run it remotely on another computer using SSH and scare its user!

echo 1+1|bc
x=; whois $x > $x.txt
2011-01-17 03:33:49
User: sxiii
Functions: whois

This can be used in scripts, to find out the origin of target IP etc.