Hide

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.

Hide

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:

Hide

News

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.
Hide

Tags

Hide

Functions

Commands using echo from sorted by
Terminal - Commands using echo - 1,259 results
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
-2

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
1

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
2

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
0

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
7

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

while read line; do echo -e "$line@mail.com"; 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
echo 'ibase=10; obase=2; 127' | bc
echo 16i `echo "F" | tr '[a-f]' '[A-F]'` p | dc ; echo 16o "15" p | dc
for i in $(seq 1 50) ; do echo Iteration $i ; done
2009-02-08 23:03:31
User: abcde
Functions: echo seq
8

Optionally, one can use {1..50} instead of seq. E.g. for i in {1..50} ; do echo Iteration $i ; done

echo -n m{1..5}.cluster.net | xargs -d' ' -n1 -P5 -I{} ssh {} 'uptime'
sudo echo 1 > /proc/acpi/asus/camera
2009-02-07 21:57:01
User: orie
Functions: echo sudo
0

In some applications on eeepc xandros 7, default OS, video ccamera is not available untill you enter this command

echo "Xc" | tr "Xo" "\033\017
now=`date +"%Y/%m/%d" -d "04/02/2005"` ; end=`date +"%Y/%m/%d" -d "07/31/2005"`; while [ "$now" != "$end" ] ; do now=`date +"%Y/%m/%d" -d "$now + 1 day"`; echo "$now"; done
echo SSBMb3ZlIFlvdQo= | base64 -d
alias scd='dirs -v; echo -n "select number: "; read newdir; cd -"$newdir"'
(sed 's/^/x+=/' [yourfile] ; echo x) | bc
2009-02-06 08:25:43
User: michelem
Functions: echo sed
7

If you have a file full of numbers written line by line, you can sum every line to get the total.

With a file like this:

3443535

9878977

67554

987798

232324

you will got:

14610188

f="FILE";c="CMD";s="stat -f %m $f";t=`$s`;while [ 1 ];do if [ $t -eq `$s` ];then sleep 1;else echo `$c`;t=`$s`;fi;done
echo '2^2^20' | time bc > /dev/null
2009-02-06 02:31:55
User: mkc
Functions: bc echo time
1

This is a quick and dirty way to generate a (non-floating-point) CPU-bound task to benchmark. Adjust "20" to higher or lower values, as needed. As a benchmark this is probably a little less bogus than bogomips, and it will run anywhere 'bc' does.

myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
2009-02-05 22:13:43
User: stuart
Functions: echo sleep
1

This will ring the system bell once if your script exits successfully and twice if it fails. So you can go look at something else and it will alert you when done. Don't forget to use 'xset b [vol [pitch [duration]]]' to get the bell to sound the way you want.

cd ~/.purple/logs/; egrep -ri "i can haz|pwn|l33t|w00|zomg" * | cut -d'/' -f 3 | sort | uniq | xargs -I {} echo "Note to self: ban user '{}'"
echo "import random; print(random.choice(['heads', 'tails']))" | python