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.

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:



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.

Top Tags



Commands using echo from sorted by
Terminal - Commands using echo - 1,274 results
echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"
2009-02-19 14:15:31
User: stinger
Functions: echo

above line in .bash_profile will give you window title in putty or terminal client when you login to your remote server

echo 1+1|bc
while true; do read i; echo $[$i]; done
2009-02-18 23:13:09
User: mulad
Functions: echo read

The $[...] block in bash and zsh will let you do math.

echo $[6*7]

This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.

for (( i = 10; i > 0; i-- )); do echo "$i"; sleep 1; done
2009-02-18 20:31:46
User: mestr
Functions: echo sleep

Countdown from 10 or whatever you want:)

unset files i; set -f; O=$IFS; while IFS= read -r -d $'\0' files[i++]; do :; done < <(find . -name '*.avi' -print0) && IFS=$O; set +f && echo "Running: mplayer \"${files[ $(( $RANDOM % ${#files[@]} )) ]}\""
2009-02-18 16:53:57
User: DEinspanjer
Functions: echo find read set unset

unsets variables used by the one-liner

sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion

uses read to slurp the results of the find command into an array

selects an element of the array at random to be passed as an argument to mplayer

echo "foo bar" | sudo tee -a /path/to/some/file
2009-02-18 13:54:25
User: raphink
Functions: echo sudo tee

This is the solution to the common mistake made by sudo newbies, since

sudo echo "foo bar" >> /path/to/some/file

does NOT add to the file as root.


sudo echo "foo bar" > /path/to/some/file

should be replaced by

echo "foo bar" | sudo tee /path/to/some/file

And you can add a >/dev/null in the end if you're not interested in the tee stdout :

echo "foo bar" | sudo tee -a /path/to/some/file >/dev/null
echo "^[]0;My_Title_Goes _Here^G"
2009-02-17 20:46:06
User: TheNomad
Functions: echo

If you are using an xterm emulation capable terminal emulator, such as PuTTY or xterm on Linux desktop, this command will replace the title of that terminal window. I know it is not nice to have seventeen terminals on your desktop with title PuTTY, you can not tell which one is connected to which server and doing what.

Even though the string between the quotes is typed as literals, it needs a little more finesse to make it work. Here is how it is done key-by-key:

echo "( ctrl-v then ctrl-[ )0;Enter_Title_String_Here( ctrl-v then ctrl-g )"( enter )

ctrl-v : means hold down ctrl key and hit v at the same time like you are pasting in windoze ; also please don't type the parentheses, i.e., ( and )

echo $RANDOM
echo foo bar foobar barfoo && echo !$ !^ !:3 !* && echo /usr/bin/foobar&& echo !$:h !$:t
2009-02-17 09:10:17
User: lhb
Functions: echo

When expanding, bash output the command, so don't be affraid if you type the command.

Here is the details:

First examples:

echo foo bar foobar barfoo

First argument:

echo !$

echo barfoo


(Note that typing echo foo bar foobar barfoo && echo !$, bash substitute !$ with $:1)

Last argument:

echo foo bar foobar barfoo && echo !^

echo foo bar foobar barfoo && echo barfoo

foo bar foobar barfoo


All the arguments:

echo !*

echo foo bar foobar barfoo

foo bar foobar barfoo

The third argument:

echo foo bar foobar barfoo && echo !:3

echo foo bar foobar barfoo && echo foobar

foo bar foobar barfoo


You may want to add {} for large numbers: echo !:{11} for example

Now with path:

echo /usr/bin/foobar


For the head:

echo !$:h

echo /usr/bin


And the tail:

echo !$:t

echo foobar


You also may want to try !:h and !:t or !!3-4 for the third and the fourth (so !!:* == !!:1-$)

for i in `seq -f %03g 5 50 111`; do echo $i ; done
2009-02-17 08:41:44
User: lhb
Functions: echo

seq allows you to format the output thanks to the -f option. This is very useful if you want to rename your files to the same format in order to be able to easily sort for example:

for i in `seq 1 3 10`; do touch foo$i ;done


ls foo* | sort -n






for i in `seq -f %02g 1 3 10`; do touch foo$i ;done


ls foo* | sort -n





START=20; END=50 echo $(($START+(`od -An -N2 -i /dev/random`)%($END-$START+1)))
2009-02-17 05:05:30
User: pyrho
Functions: echo

This commands lets you generate a random number between the range [$START; $END].

echo *
2009-02-16 21:20:13
User: grep
Functions: echo

I know its not much but is very useful in time consuming scripts (cron, rc.d, etc).

echo "<?php phpinfo(); ?>" | php > phpinfo.txt
echo "SELECT * FROM table; " | mysql -u root -p${MYSQLROOTPW} databasename | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > outfile.csv
2009-02-16 18:55:18
Functions: echo sed

This command converts a MySQL query directly into a .csv (Comma Seperated Value)-file.

echo "sed -e"|perl -pe 's/sed -e/perl -pe/'
2009-02-16 18:39:06
User: drossman
Functions: echo

Replace sed regular expressions with perl patterns on the command line.

The sed equivalent is: echo "sed -e"|sed -e 's/sed -e/perl -pe/'

echo "Set Twitter Status" ; read STATUS; curl -u user:pass -d status="$STATUS" http://twitter.com/statuses/update.xml
2009-02-16 14:34:05
User: ronz0
Functions: echo read

Modify the script for your username and password, and save it as a script. Run the script, and enjoy ./tweet

for (( i = 0; i < 100; i++ )); do echo "$i"; done
2009-02-16 03:19:26
User: themattrix
Functions: echo

Print 0 through 99, each on a separate line.

echo 'example' | sed -e 's/^\(.\)/\U\1/'
echo $(( (1234567890 - `date -u +\%s`) / 60 / 60 ))
echo $PATH | tr : \\n
2009-02-13 15:54:58
User: piyo
Functions: echo tr

This works in bash and zsh.

You may also want to alias it, if you need to look at it often...

alias lpath="echo \$PATH | tr : \\\\n"

"\$PATH" to make sure to look at your current $PATH

svn st | grep /main/java | awk '{print $2}' | xargs echo | xargs svn ci -m "my comment here"
for ip in $(seq 1 25); do ping -c 1 192.168.0.$ip>/dev/null; [ $? -eq 0 ] && echo "192.168.0.$ip UP" || : ; done
2009-02-11 14:57:34
Functions: echo ping seq

this is very useful when there is a different network host to determine which are turned on or not

echo $0
2009-02-11 08:58:01
User: yogsototh
Functions: echo

Return the current shell. It is better than print $SHELL which can sometimes return a false value.

while read line; do echo -e "$[email protected]"; done < list.txt
i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done