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 sleep from sorted by
Terminal - Commands using sleep - 243 results
while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" != 1 ] && beep; sleep 1; done
2009-03-31 20:47:56
User: sudopeople
Functions: sleep

pings a server once per second, and beeps when the server is unreachable.

Basically the opposite of:

ping -a server-or-ip.com

which would beep when a server IS reachable.

You could also substitute beep with any command, which makes this a powerful alternative to ping -a:

while true; do [ "$(ping -c1W1w1 server-or-ip.com 2>/dev/null | awk '/received/ {print $4}')" = 1 ] && date || echo 'server is down!'; sleep 1; done

which would output the date and time every sec until the ping failed, in which case it would echo.


Requires beep package.

May need to run as root (beep uses the system speaker)

Tested on Ubuntu which doesn't have beep out of the box...

sudo apt-get install beep
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
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
while true; do date; sleep 1; done
2009-03-23 22:44:59
User: cbetts
Functions: sleep

Handy if all you have is a console session or tty.

lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
2009-03-13 13:17:53
User: garylittle
Functions: sleep

Lockstat will sample the kernel 977 times per second, and print out the functions that it sees executing on the CPU during the sample. The -s 10 switch tells lockstsat to not only print that function, but also show the call stack (up to 10 deep).

for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && echo "bye, bye" && shutdown -h now
2009-03-13 12:16:35
User: arctarus
Functions: bc echo seq shutdown sleep

command to turn off your computer when you go home and can not wait

for person in Alex Bruce Fred Kathy Vicki Victoria ; do say -v $person "Hello, my name is $person"; sleep 1; done
2009-03-09 15:42:13
User: haivu
Functions: sleep
Tags: Os X

Listen to different voices in the system--useful for picking the voice you like

doloop() { DONT=/tmp/do-run-run-run; while true; do touch $DONT; (sleep 30; rm $DONT;) & $1 ; if [ -e $DONT ]; then echo restarting too fast; return ; fi ; done }
2009-02-21 02:11:18
User: evil_otto
Functions: echo return rm sleep touch

This runs a command continuously, restarting it if it exits. Sort of a poor man's daemontools. Useful for running servers from the command line instead of inittab.

while [ 1 ]; do curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss|grep title|sed -ne 's/<\/*title>//gp' | head -n 6 |festival --tts; sleep 300;done
2009-02-20 20:20:21
User: tomwsmf
Functions: head sleep

Pump up the chatter, run this script on a regular basis to listen to your twitter timeline.

This is a rough first cut using several cli clips I have spotted around. There is no facility to not read those things already read to you. This could also easily be put in a loop for timed onslaught from the chatterverse, though I think it might violate several pointsof the Geneva Convention

UPDATE - added a loop, only reads the first 6 twits, and does this every 5 mins.

$(STEEP=300; sleep $STEEP; xmessage "Your tea is done") &
2009-02-19 20:10:49
User: sud0er
Functions: sleep

wrapping the snippet in $( )& puts the whole thing in the background so you don't tie up your login session.

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:)

while [ 0 ]; do expr 2365200000 \- `date +%s` \- `date --date "YYYY-mm-dd HH:MM:ss" +%s`; sleep 1; clear; done
2009-02-13 20:02:37
User: wwest4
Functions: expr sleep

watch the seconds of your life tick away - replace YYYY-mm-dd HH:MM:ss w/ your birthtime.

sleep 3m; play bigben.wav
2009-02-13 13:20:13
User: legba7
Functions: sleep

plays wave file after 3 minutes

while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -R 2222:localhost:22 target "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done
while [ 1 ]; do date; ls -l /path/to/dir; sleep 1; done
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
myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
2009-02-05 22:13:43
User: stuart
Functions: echo sleep

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.

yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done