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 sleep from sorted by
Terminal - Commands using sleep - 234 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
-1

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
1

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
User: SQUIIDUX
Functions: cat read sleep sudo
Tags: cat streamer
4

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.

Ideas:

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" 4158575309@txt.att.net`
2012-04-16 01:28:16
User: vajrapani666
Functions: mail sleep
-1

Replace "4158575309@txt.att.net" 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: khopesh
Functions: echo head set sleep
0

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.

Enjoy!

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: $@"; date; eval "$@"; sleep 2; done }
2012-03-07 09:30:15
User: hfs
Functions: echo eval sleep watch
Tags: watch
0

Usage:

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
0

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
0

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: $@ \t\t\t\t $date"; echo $@; 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
0

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
1

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
Functions: sleep
Tags: audio bash timer
5

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
0

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
1

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
-3

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
0

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
7

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
-2

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
-2

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
9

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
2

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.