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,228 results
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
echo -n "search> ";read QUERY && wget -O - `wget -O - -U "Mozilla/5.0" "http://images.google.com/images?q=${QUERY}" 2>/dev/null |sed -e 's/","http/\n","http/g' |awk -F \" '{print $3}' |grep -i http: |head -1` > "$QUERY"
2009-02-05 19:50:53
User: wwest4
Functions: echo wget
2

prompts for a search term and then pulls down the first result from google images

echo -n search\>\ ; read SEARCH_STRING && sed -n "/$SEARCH_STRING/{n;p;n;p;n;p;q}" [file-to-search]
2009-02-05 18:07:23
User: wwest4
Functions: echo read sed
0

customizable context searches - if you know sed, this is a basis for more complex context control than grep --context offers

echo | openssl s_client -connect www.google.com:443 2>/dev/null |openssl x509 -dates -noout
2009-02-05 15:21:50
User: systemj
Functions: echo
30

remotely connects to an https site, fetches the ssl certificate and displays the valid dates for the cert

NAME=$(nslookup $IP | sed -n 's/.*arpa.*name = \(.*\)/\1/p'); test -z "$NAME" && NAME="NO_NAME"; echo "$NAME"
for i in *.bak ; do nuname=`echo $i | sed 's/\.[^\.]*$//'`; echo renaming $i to $nuname;mv $i $nuname; done
echo "SHOW PROCESSLIST\G" | mysql -u root -p | grep "Info:" | awk -F":" '{count[$NF]++}END{for(i in count){printf("%d: %s\n", count[i], i)}}' | sort -n