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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using sleep from sorted by
Terminal - Commands using sleep - 255 results
slow () { [ -n $1 ] && while kill -STOP $1; do sleep 1; kill -CONT $1; sleep 1; done }
2012-05-16 19:16:50
User: makidoko
Functions: kill sleep
Tags: io

compare to alternative :

- directly tests the -STOP of the process to continue or stop loop,

- background operator should be set (or not) at the call of the function

For extension i suggest a slowPID() based on kill like above and a slowCMD based on killall.

slow () { [ -n $1 ] && while ps -p $1 >/dev/null ; do kill -STOP $1; sleep 1; kill -CONT $1; sleep 1; done & }
2012-05-16 12:13:30
User: igorfu
Functions: kill ps sleep
Tags: io

Some IO intensive process make the system unresponsive. This function periodically starts/stops a process, which hopefully releases some resources for other activities.

This function is useful when ionice is not available

while true; do sudo cat /dev/input/mouse0|read -n1;streamer -q -o /tmp/cam.jpeg -s 640x480 > /dev/null 2>&1; sleep 10;done
2012-04-22 01:51:30
Functions: cat read sleep sudo
Tags: cat streamer

This takes a webcam picture every everytime the mouse is moved (waits 10 seconds between checking for movement) and stores the picture wherever you want it.


Use in conjunction with a dropbox type application to see who is using your computer

Use /dev/input/mice if /dev/input/mouse* doesn't work

Use the bones of this to make a simple screensaver

sleep 15 ; `echo "done" | mail -s "done" [email protected]`
2012-04-16 01:28:16
User: vajrapani666
Functions: mail sleep

Replace "[email protected]" with your carrier's SMS gateway identifier. The one in the sample is for AT&T. More here https://en.wikipedia.org/wiki/List_of_SMS_gateways. Helpful for getting notifications about long running commands. ";" executes regardless of exit status of last command. && will only notify you if the command succeeds.

(set -o noglob;while sleep 0.05;do for r in `grep -ao '[[:print:]]' /dev/urandom|head -$((COLUMNS/3))`;do [ $((RANDOM%6)) -le 1 ] && r=\ ;echo -ne "\e[$((RANDOM%7/-6+2));32m $r ";done;echo;done)
2012-04-13 02:09:10
User: adamhotep
Functions: echo head set sleep

A tweak using Patola's code as a base, this full-width green matrix display has all the frills (and all the printable characters).

You don't need the surrounding parens if you don't care about losing globbing capabilities. Z-shell (/bin/zsh) needs neither the parens nor the `set -o noglob`

Screen shot (animated): http://desmond.imageshack.us/Himg32/scaled.php?server=32&filename=matrixh.gif&res=landing

If it's too slow, try lowering the `sleep 0.05` or even replacing it with `true` (which is faster than `sleep 0`).

I squashed it as narrow as I could to conserve space, though somebody could probably squeeze a char or two out.


yes "$(seq 232 255;seq 254 -1 233)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
while [ 1 ]; do tail /var/log/httpd/error_log; sleep 2; clear; done
watch() { while true; do echo "<Ctrl+V><Ctrl+L>Every 2.0s: [email protected]"; date; eval "[email protected]"; sleep 2; done }
2012-03-07 09:30:15
User: hfs
Functions: echo eval sleep watch
Tags: watch


watch ls -l

Basic but usable replacement for the "watch" command for those systems which don't have it (e.g. the Solaris I'm trapped on).

Type Ctrl+V to escape the following Ctrl+L which clears the screen. It will be displayed as "^L".

for ((x=0;;x+=5)); do sleep 5; hours=$(($x/3600)); minutes=$(($x%3600/60)); seconds=$(($x%60)); echo "$hours hours $minutes minutes $seconds seconds have elapsed" | festival --tts & done
2012-03-06 22:58:43
User: mrklaw
Functions: echo sleep

Says time every 5 seconds in hours, minutes and seconds using festival.

for ((x=0;;x+=5)); do sleep 5; echo $x | festival --tts & done
2012-03-06 21:17:51
User: mrklaw
Functions: echo sleep

works the same, but uses festival instead of espeak

watch() { if [ -z "$1" ]; then echo "usage: watch interval command" return fi sec=$1 shift while test :; do clear; date=$(date); echo -e "Every "$sec"s: [email protected] \t\t\t\t $date"; echo [email protected]; sleep $sec; done }
r="readlink /proc/`pgrep -o mplayer`/fd/3";while [ -e "`$r`" ];do if [ "$f" = "`$r`" ];then sleep 1;else f="`$r`";notify-send " $f";fi;done
2012-02-26 06:49:16
User: aix
Functions: sleep

Will finish automagically when mplayer quits. Can be run from any directory.

It seems to finish by it self rarely, probably because of some timing issue? There's probably a way around that which I can't think of right now

dd if=/dev/urandom of=file.img bs=4KB& sleep 1 && pid=`pidof dd`; while [[ -d /proc/$pid ]]; do kill -USR1 $pid && sleep 10 && clear; done
2012-02-23 01:45:53
Functions: dd kill sleep

The previously-posted one-liner didn't work for me for whatever reason, so I ended up doing this instead.

for ((x=0;;x+=5)); do sleep 5; espeak $x & done
2012-02-22 00:26:57
User: adeverteuil
Functions: sleep
Tags: audio bash timer

Useful contexts :

You are doing yoga or some other physical training in which you are holding a position.

Or you practice the pomodoro productivity technique.

Or your girlfriend said "We're leaving in 40 minutes".

Design details:

sleep executes before espeak to give you a 5 seconds head start.

espeak is run in the background so it doesn't mess up the timing.

export GREP_COLOR='1;32';while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep --color=auto "ca fe"
sayspeed() { for i in $(seq 1 `echo "$1"|wc -c`); do echo -n "`echo $1 |cut -c ${i}`"; sleep 0.1s; done; echo "";}
2012-02-11 05:51:42
User: kundan
Functions: echo seq sleep wc

change the time that you would like to have as print interval

and just use it to say whatever you want to

while true; do curl -s http://sensiblepassword.com/?harder=1 | tail -n 15 | head -n 1 | sed 's;<br/>;;' | cut -c 5- | cb; sleep 1; done
2012-01-30 20:52:14
User: supervacuo
Functions: cut head sed sleep tail

Use the excellent sensiblepasswords.com to a generate random (yet easy-to-remember) password every second, and copy it to the clipboard. Useful for generating a list of passwords and pasting them into a spreadsheet.

This script uses "madebynathan"'s "cb" function (http://madebynathan.com/2011/10/04/a-nicer-way-to-use-xclip/); you could also replace "cb" with

xclip -selection c

Remove "while true; do" and "; done" to generate and copy only 1 password.

for i in `wget -O url|grep '<a rel="nofollow"'|grep http|sed 's|.*<a rel="nofollow" class="[^"]\+" href="[^"]*https\?://\([^/]\+\)[^"]*">[^<]\+</a>.*|\1|'`;do if test -n "$(whois $i|grep -i godaddy)";then echo $i uses GoDaddy;fi;sleep 20;done
check(){ power=$(acpi -a) ; if [[ $power == *on-line* ]] ; then echo "supply is on"; else echo "somebody is steeling your laptop"; amixer -c0 set Master 100+ unmute ; mpg123 nuclear-alarm.mp3 ; fi } ;while true; do check ; sleep 2 ; done
2011-12-10 13:42:52
User: hoodie

Checks whether your power supply is still plugged in.

If not it will trigger an alarm at maximum volume.

man -t man | ps2pdf - temp.pdf; evince temp.pdf &> /dev/null &; sleep 3; rm temp.pdf
2011-12-08 17:40:47
User: threv
Functions: man rm sleep

Yeah yeah, another "render man page in pdf", but this time it creates a temporary PDF that stays resident in memory for viewing, but is eliminated on the filesystem.

Replace evince with your PDF viewer of choice.

at 8:30 <<<'mpc volume 20; mpc play; for i in `seq 1 16`; do sleep 2; mpc volume +5; done'
2011-11-30 17:51:27
User: mechmind
Functions: at sleep
Tags: alarm mpd wakeup

There are a lot of commands, which invokes your player at specified time. But I prefer not to jump from by bed, when alarm start to play. Instead, this script increases volume of mpd over time, which much more pleasant when you just woke up :)

for file in ./*; do cat "$file"; sleep 0.3
2011-11-28 20:10:57
User: DopeGhoti
Functions: cat file sleep

Original submitted version would break if any filenames had whitespaces in them. The command is a Bad Idea anyhow, because you will end up `cat`ing a binary or something else specacularly bad.

for f in *; do clear; cat $f; sleep .3; done
2011-11-25 17:10:47
User: toddkaufmann
Functions: cat sleep

The better alternative to #9756.

I don't think I'd ever use the original command, but this one was so bad I had to post this. Sorry.

1. $(ls) is dumb, and will give errors if you have an alias like "ls -Fs"

2. clear is better and more portable than reset state.

3. if you're interested in differences, then use diff, not cat.

while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = $2 - oi; o = $10 - oo; oi = $2; oo = $10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
2011-11-21 05:24:44
Functions: awk cat printf sleep
Tags: awk sh

poorman's ifstat using just sh and awk. You must change "eth0" with your interface's name.

for line in `cat $file`; do firefox -new-tab "$line" & 2>/dev/null; sleep 1; done
2011-11-12 13:47:24
User: hamsolo474
Functions: sleep

this will open a new tab in firefox for every line in a file

the sleep is removable but i found that if you have a large list of urls 50+, and no sleep, it will try to open all the urls at once and this will cause them all to load a lot slower, also depending on the ram of your system sleep gives you a chance to close the tabs before they overload your ram, removing & >2/dev/null will yield unpredictable results.