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.




Commands using echo from sorted by
Terminal - Commands using echo - 1,208 results
while true; do X=$Y; sleep 1; Y=$(ifconfig eth0|grep RX\ bytes|awk '{ print $2 }'|cut -d : -f 2); echo "$(( Y-X )) bps"; done
function svnundopoint() { if [ -d .undo ]; then r=`svn info | grep Revision | cut -f 2 -d ' '` && t=`date +%F_%T` && f=${t}rev${r} && svn diff>.undo/$f && svn stat>.undo/stat_$f; else echo Missing .undo directory; fi }
2009-03-27 07:14:31
User: codeape
Functions: cut echo grep info
Tags: bash svn

Allows you to save progress without committing.

To revert to an undo point, svn revert then apply the undo point with patch.

svn revert -R . && patch -p0 < .undo/2009-03-27_08:08:11rev57

Similar: http://www.commandlinefu.com/commands/view/373/archive-all-files-containing-local-changes-svn

echo '!'whammy
2009-03-26 23:34:33
User: sudopeople
Functions: echo
Tags: literal bang

Seems obvious, but other seemingly simple ways to use it don't work:

echo !whammy


echo "!whammy"

both output:

-bash: !whammy: event not found

and this:

echo "\!whammy"



with the slash :(

you can also do any combinations of quotes for a complex string:

echo "It's great to be able to use a bang ("'!'") in a command"'!'


It's great to be able to use a bang (!) in a command!
while [ 1 ]; do echo -n "`date +%F_%T`" ; vmstat 1 2 | tail -1 ; sleep 4; done
2009-03-26 19:16:55
User: plasticboy
Functions: echo sleep tail vmstat

See man vmstat for information about the statistics.

This does the same thing without the timestamp:

vmstat 5
scrot -e 'mv $f \$HOME/shots/; sitecopy -u shots; echo "\$BASE/$f" | xsel -i; feh `xsel -o`'
2009-03-26 12:08:39
User: penpen
Functions: echo

Here $HOME/shots must exist and have appropriate access rights and sitecopy must be correctly set up to upload new screen shots to the remote site.

Example .sitecopyrc (for illustration purposes only)

site shots

server ftp.example.com

username user

password antabakadesuka

local /home/penpen/shots

remote public_html/shots

permissions ignore

The command uses scrot to create a screen shot, moves it to the screen shot directory, uploads it using screen uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.

Note that $BASE stands for the base URL for the screen shots on the remote server, replace it by the actual location; in the example http://www.example.com/~user/shots would be fitting.

Assign this command to a key combination or an icon in whatever panel you use.

scrot -e 'mv $f \$HOME/public_html/shots/; echo "http://\$HOSTNAME/~\$USER/shots/$f" | xsel -i; feh `xsel -o`'
2009-03-26 11:32:09
User: penpen
Functions: echo

A web server using $HOME/public_html as user directory is required, $HOME/public_html/shots must exist and have appropriate access rights and $HOSTNAME must be known to and accessible from the outside world.

The command uses scrot to create a screen shot, moves it to the screen shot directory, uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.

Assign this command to a key combination or an icon in whatever panel you use.

echo "obase=2; 27" | bc -l
2009-03-25 09:54:50
User: polar
Functions: bc echo
Tags: bc

Easily convert numbers to their representations in different bases. Passing

"ibase=16; obase=8; F2A"

to bc will convert F2A (3882 in decimal) from Hex to Octal, and so on.

echo "$math_expr" | bc -l
2009-03-25 09:46:01
User: polar
Functions: bc echo
Tags: bc

Useful for quick calculations at the command line. $math_expr is any arithmetic expression (see sample output):



More options in the bc man page.

echo -e "[client]\nuser = YOURUSERNAME\npassword = YOURPASSWORD" > ~/.my.cnf
2009-03-24 19:05:39
User: alperyilmaz
Functions: echo
Tags: mysql bash

The file .my.cnf located at user's home directory is used for mysql login. If this file exists, then


can be replaced with

mysql database -e 'SOME SQL COMMAND'

It saves you from typing!

This is valid for mysqladmin and mysqldump commands as well.

for i in `find . | grep jar$`; do echo $i; jar tvf $i | grep 'search-string'; done;
alias mux='clear && cd ~/Music/ && ls && echo -n "File> " && read msi && mplayer ~/Music/$msi'
2009-03-23 10:45:27
User: Noxn
Functions: alias cd echo ls read

An alias i made for myself to play music in a faster way.

Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)


I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.


Needs Mplayer and music files to work. With out music theres nothing to play!

Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.

ls | while read ITEM; do echo "$ITEM"; done
2009-03-22 23:33:13
User: fletch
Functions: echo ls read
Tags: bash

If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):

for ITEM in `ls`; do echo "$ITEM"; done

Instead, use a while loop with `read`:

ls | while read ITEM; do echo "$ITEM"; done
for i in {1..15}; do echo $i; done
2009-03-21 23:08:41
User: haivu
Functions: echo
Tags: bash

The brace expansion also allows you to count backward:

for i in {15..1}; do echo $i; done

You can also use this construct to create new file or new directory:

mkdir dir{1..3} # Same as mkdir dir1 dir2 dir3

echo 'wget url' | at 01:00
2009-03-21 06:19:40
User: Vlad003
Functions: at echo

Replace "url" with the correct address of what your're downloading. Replace 01:00 with what time you want. (24-hour clock).

ls -1 static/images/ | while read line; do echo -n $line' '[; grep -rc $line *|grep -v ".svn"|cut -d":" -f2|grep -vc 0| tr "\n" -d; echo -n ]; echo ; done
2009-03-20 20:33:36
User: psytek
Functions: cut echo grep ls read tr

This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.

echo ${file##*/}
if [ "${vote}" = "down" ]; then echo leave comment; fi
2009-03-20 00:31:13
Functions: echo

I think it would be wise if anyone voting down left a comment indicating the reason for that action. Don't keep it to yourself. Thanks.

( IFS=:; for p in $PATH; do echo $p; done )
2009-03-19 22:45:47
User: haivu
Functions: echo
Tags: bash

The output of "echo $PATH" is hard to read, this is much easier. The parentheses ensure that the change to the input field separator (IFS) only happens the the sub shell and not affecting the current shell.

echo 'loginname ALL=(ALL) ALL' >> /etc/sudoers
2009-03-19 13:23:43
User: refrax
Functions: echo

I am new to linux, and I was trying to figure out why I could not sudo with my username in Fedora 10. This command, when run as root, will add a line to the sudoers file allowing the loginname supplied to sudo. The above line will require a password when you sudo, if you wish to sudo without password, use:

echo 'loginname ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

instead. you have to run this command as su, and this is just an easier way of using visudo, just adds it right from the terminal.

echo "- - -" > /sys/class/scsi_host/host0/scan
2009-03-18 15:26:42
User: angrox
Functions: echo

Issues a scan command on the given scsi host adapter (ex. a fibre channel adapter, in the example above on host0). Output can be watched in the messages log or in "dmesg"

echo '123/7' |bc -l |xargs printf "%.3f\n"
echo -n 'text to be encrypted' | openssl md5
2009-03-18 00:11:46
User: Zenexer
Functions: echo

Thanks to OpenSSL, you can quickly and easily generate MD5 hashes for your passwords.

Alternative (thanks to linuxrawkstar and atoponce):

echo -n 'text to be encrypted' | md5sum -

Note that the above method does not utlise OpenSSL.

echo "test" | lp -d $PRINTER
2009-03-17 20:07:41
User: nauseaboy
Functions: echo lp

This will send a test print job to a networked printer.

for i in `find /sys/devices/*/*/usb* -name level` ; do echo -n "$i: " ; cat $i ; done
echo "encryptedpassword"|openssl passwd -1 -stdin