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,221 results
while [[ 1 ]]; do n=( */* ); s=${n[$(($RANDOM%${#n[@]}))]}; echo -e " - $s"; mpg123 -q "$s"; done
2013-01-18 09:20:58
User: XayOn
Functions: echo mpg123

Play files in shuffle mode with bash and mpg123.

Why bother using big-as-hell stuff like mplayer? This will play all your music files contained in */* (in my case author/song.format) with bash and mplayer showing a nice output.

mkalias () { echo "alias $1=\"$2\"" >> ~\.bash_aliases }
2013-01-14 13:56:35
User: xr09
Functions: echo
Tags: alias function

Is used like this:

mkalias rmcache "rm -rfv app/cache/*"

find . | while read line; do test `stat -c %u $line` -eq 1003 && chown android:android $line && echo $line; done
if date -d 2006-10-10 >> /dev/null 2>&1; then echo 1; else echo 0; fi
2013-01-10 10:35:15
Functions: date echo

On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates.

-d, --date=STRING display time described by STRING, not `now'

The version of date on OS X does not appear to have this same option.

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i >>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
2013-01-09 21:48:23
User: r0nd0n
Functions: echo gcc

Something I pulled off 4chan, it plays a tune.

echo -e "You are a jerk\b\b\b\bwonderful person" | pv -qL $[10+(-2 + RANDOM%5)]
2013-01-09 19:18:07
User: joeheyming
Functions: echo

The output will show jerk, then wonderful person since echo parses the \b character.

echo "|MENU| |DOWN| |UP/BRIGHT| |ENTER| |AUTO| |OFF|"|osd_cat -p bottom -o -40 -i 1575
2013-01-02 07:45:54
User: hawo
Functions: echo

I often need to change the brightness of my monitor. The symbols of the sensor buttons are not illuminated and on a black background .... invisible!

Now i use osd_cat instead of a torch ;-)

echo 'flush_all' | nc localhost 11211 -i1 <<< 'quit'
while sleep 1; do (mpc status;mpc currentsong)|awk 'BEGIN{FS=": "}/^Artist:/{r=r""$2};/^Title:/{r=r" - "$2};/^time:/{r=$2" "r};/^state: play/{f=1}END{if(f==1){print r}}'|echo -ne "\e[s\e[0;0H\e[K\e[0;44m\e[1;33m$(cat -)\e[0m\e[u";done &
2012-12-24 18:03:29
User: ichbins
Functions: awk echo sleep
Tags: bash mpd,

Actually this is a shorter version that fits the 255 chars limit of this resource. The full version shows status in the right top corner:

alias mpdd='while sleep 1; do _r=$(awk '\''BEGIN{FS=": "}/^Artist:/{r=r""$2};/^Title:/{r=r" - "$2};/^time:/{r=$2" "r};/^state: play/{f=1}END{if(f==1){print r}}'\'' <(mpc status;mpc currentsong));_l=${#_r};[ $_l -eq 0 ] && continue;[ -z "$_p" ] && _p=$_l;echo -ne "\e[s\e[0;${_p}H\e[K\e[u";_p=$((COLUMNS - _l));echo -ne "\e[s\e[0;${_p}H\e[K\e[0;44m\e[1;33m${_r}\e[0m\e[u";done &'

mpc is defined like this:

function mpc() {

echo "$*" | nc 6600


find . -type d | while read dir ; do num=`ls -l $dir | grep '^-' | wc -l` ; echo "$num $dir" ; done | sort -rnk1 | head
scrotit(){ echo "Screenshot in $1 seconds...";scrot -d $1 '%Y%m%d%h.png' -e 'curl -sF file1=@- http://ompldr.org/upload < $f | grep -P -o "(?<=File:).*(http://ompldr.org/.*)\<\/a\>";rm $f'| sed -r 's@.*(http://ompldr.org/\w{1,7}).*@\1@';}
2012-12-03 01:21:19
User: dzup
Functions: echo grep rm sed

Take a screenshot, give $1 seconds pause to choose what to screenshot, then upload and get URI of post in ompdlr.org

echo $((RANDOM % 10 + 1))
2012-11-21 13:49:53
User: putnamhill
Functions: echo
Tags: bash

If you don't have seq or shuf, bash can be used.

while true;do n="$(curl -s http://news.yahoo.com/rss/|sed 's/</\n/g'|grep "title>"|sed -e '/^\// d' -e 's/title>/---------- /g' -e '1,3d'|tr '\n' ' ')";for i in $(eval echo {0..${#n}});do echo -ne "\e[s\e[0;0H${n:$i:$COLUMNS}\e[u";sleep .15;done;done &
2012-11-17 23:56:17
Functions: echo eval sleep

This creates a permanent stock ticker in the terminal. it has scrolling action and refreshes when each cycle is done to get the latest news.

for file in `ls -t \`find . -name "*.zip" -type f\``; do found=`unzip -c "$file" | grep --color=always "PATTERN"`; if [[ $found ]]; then echo -e "${file}\n${found}\n"; fi done
2012-11-12 15:43:15
User: vladfr
Functions: echo file grep

for file in `ls -t \`find . -name "*.zip" -type f\``; do

found=`unzip -c "$file" | grep --color=always "PATTERN"`;

if [[ $found ]]; then echo -e "${file}\n${found}\n"; fi


while true; do echo -ne "\e[s\e[0;$((COLUMNS-27))H$(date)\e[u"; sleep 1; done &
2012-11-11 02:16:21
Functions: echo sleep

This puts a clock in the top right of the terminal. This version doesn't use tput, but uses escape codes

echo "your string here" | tr '\!-~' 'P-~\!-O'
2012-11-06 12:49:00
User: DevEd
Functions: echo tr

This command will encode a string using the ROT47 cipher.

java -jar app.jar -cp $(echo lib/*.jar | tr ' ' ':')
2012-10-29 12:51:46
User: xymor
Functions: echo tr
Tags: java cli

Lauching an app including jars in an adjacent lib folder to its classpath

for k in `git branch -r|awk '{print $1}'`;do echo -e `git show --pretty=format:"%Cgreen%ci_%C(blue)%c r_%Cred%cn_%Creset" $k|head -n 1`$k;done|sort -r|awk -F"_" '{printf("%s %17s %-22s %s\n",$1,$2,$3,$4)}'
echo -e \\u2620
tail -f /var/log/messages.log | while read line ; do echo $line | cut -d \ -f5- | sed s/\\[[0-9]*\\]// | espeak ; done
echo /home/foo/dir1/bar | awk -F/ -v OFS=/ '{$3 = "dir2"}1'
2012-10-26 16:17:20
User: zlemini
Functions: awk echo

Awk replaces the value of a specific field while retaining the field separator "/" .

echo foo | ncat [ip address] [port]
2012-10-26 10:53:47
User: dragonauta
Functions: echo

you can use a pair of commands to test firewalls.

1st launch this command at destination machine

ncat -l [-u] [port] | cat

then use this command at source machine to test remote port

echo foo | ncat [-u] [ip address] [port]

First command will listen at specified port.

It will listen TCP. If you use -u option will listen UDP.

Second command will send "foo" through ncat and will reach defined IP and port.

for i in $(ps -eo pid|grep -v PID);do echo ""; echo -n "==$i== ";awk '/^read|^write/{ORS=" "; print}' /proc/$i/io 2>/dev/null; echo -n " ==$i=="; done|sort -nrk5|awk '{printf "%s\n%s %s\n%s %s\n%s\n\n",$1,$2,$3,$4,$5,$6}'
for i in `ls /var/log/sa/|grep -E "sa[0-9][0-9]"`;do echo -ne "$i -- ";sar -r -f /var/log/sa/$i|awk '{ printf "%3.2f\n",($4-$6-$7)*100/(3+$4)}'|grep -Eiv "average|linux|^ --|0.00|^-" |awk '{sum+=$1 }END{printf "Average = %3.2f%%\n",sum/NR}';done
echo "abcdefg"|awk 'BEGIN {FS="''"} {print $2}'