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 - 236 results
sleep 3600; amixer set Master mute
2011-02-06 03:14:33
User: kenbarbour
Functions: amixer set sleep
1

Mutes the speakers after an hour, in case you fall asleep watching a video...

while true; do curl -s http://whatthecommit.com | perl -p0e '($_)=m{<p>(.+?)</p>}s' | cowsay; sleep 2; done
while true; do lynx --dump http://whatthecommit.com/ | head -n 1 | cowsay; sleep 2; done
while sleep 1; do acpi -t | osd_cat -p bottom; done &
2011-01-14 23:22:57
User: linuts
Functions: acpi sleep
1

No need for a colon, and one less semicolon too. Also untested.

while :; do acpi -t | osd_cat -p bottom ; sleep 1; done &
2011-01-14 13:57:45
User: John_W
Functions: acpi sleep
3

There is no need for variables. I also added sleep to reduce cpu usage, however I didn't test it.

( for((i=0;$i<100;i++))do echo volume $i 1; sleep 0.1s; done; )| mplayer -slave -quiet sample.mp3
2011-01-06 11:22:03
User: Juluan
Functions: echo sleep
0

Of course, a fifo is required for piloting the fade out of another song, but with a few bash function, we can mix music in bash like :

crossfadeIn > mplayerfifo1 & crossfadeOut > mplayerfifo2

loop 0 10 > mplayer fifo1

etc etc

exipick -zi | while read x ; do exim -dM "$x"; sleep 1;done
2011-01-04 20:17:30
User: alustenberg
Functions: read sleep
Tags: exim
0

can also be invoked as 'exipick -zi | exim -dM' if you do not need/want the delay between flushes.

diff <(lsusb) <(sleep 3s && lsusb)
2010-12-27 22:46:54
User: Juluan
Functions: diff sleep
24

I often use it to find recently added ou removed device, or using find in /dev, or anything similar.

Just run the command, plug the device, and wait to see him and only him

for ((;;)) do pgrep wget ||shutdown -h now; sleep 5; done
dd if=/path/to/inputfile of=/path/to/outputfile & pid=$! && sleep X && while kill -USR1 $pid; do sleep X; done
2010-12-02 15:07:18
User: cyrusza
Functions: dd kill sleep
Tags: dd copy progress
1

Adjust "sleep X" to your needs.

*NOTE: First sleep is required because bash doesn't have a "post-test" syntax (do XXX while).

cat video.ogg | nc -l -p 4232 & wget http://users.bshellz.net/~bazza/?nombre=name -O - & sleep 10; mplayer http://users.bshellz.net/~bazza/datos/name.ogg
until foo some args; do echo "crashed: $? respawning..." >&2; sleep 10; done
2010-11-28 18:08:58
User: braddunbar
Functions: echo sleep
5

restart a buggy script when it dies. works great for "git svn fetch", which leaks memory like a sieve and eventually dies...making you restart it.

for i in $(seq 300) ; do ethtool -s eth0 autoneg on ; sleep 2 ; done
2010-10-31 18:15:54
User: christian773
Functions: seq sleep
-3

use this comand to see which switch port your network interface is using.

but remind, there is no network traffic for 10 minutes or how long you run the comand.

if you start the comand via ssh, port will come up again after the "for loop" has endet

ontouchdo(){ while :; do a=$(stat -c%Y "$1"); [ "$b" != "$a" ] && b="$a" && sh -c "$2"; sleep 1; done }
2010-10-22 23:25:12
User: putnamhill
Functions: sh sleep stat
Tags: stat
10

This is useful if you'd like to see the output of a script while you edit it. Each time you save the file the command is executed. I thought for sure something like this already exists - and it probably does. I'm on an older system and tend to be missing some useful things.

Examples:

ontouchdo yourscript 'clear; yourscript somefiletoparse'

Edit yourscript in a separate window and see new results each time you save.

ontouchdo crufty.html 'clear; xmllint --noout crufty.html 2>&1 | head'

Keep editing krufty.html until the xmllint window is empty.

Note: Mac/bsd users should use stat -f%m. If you don't have stat, you can use perl -e '$f=shift; @s=stat($f); print "$s[9]\n";' $1

cycle(){ while :;do((i++));echo -n "${3:$(($i%${#3})):1}";sleep .$(($RANDOM%$2+$1));done;}
2010-10-08 23:45:40
User: putnamhill
Functions: echo sleep
Tags: sleep random
1

Cycles continuously through a string printing each character with a random delay less than 1 second. First parameter is min, 2nd is max. Example: 1 3 means sleep random .1 to .3. Experiment with different values. The 3rd parameter is the string. The sleep will help with battery life/power consumption.

cycle 1 3 $(openssl rand 100 | xxd -p)

Fans of "The Shining" might get a kick out of this:

cycle 1 4 ' All work and no play makes Jack a dull boy.'
j=0;while true; do let j=$j+1; for i in $(seq 0 20 100); do echo $i;sleep 1; done | dialog --gauge "Install part $j : `sed $(perl -e "print int rand(99999)")"q;d" /usr/share/dict/words`" 6 40;done
2010-10-08 12:12:00
User: houghi
Functions: echo seq sleep
15

This will turn it in an infinite loop and also shows random words from a file, so it won't be the same each time and also not just a number.

for i in $(seq 0 5 100); do echo $i; sleep 1; done | zenity --progress --title "Installing Foobar" --text "Pleae wait until process has finished."
2010-10-08 04:08:33
User: zed
Functions: echo seq sleep
3

Create a progress dialog with custom title and text using zenity.

for i in $(seq 0 5 100); do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
2010-10-08 04:08:17
User: zed
Functions: echo seq sleep
3

using seq inside a subshell instead of a bash sequence to create increments.

while [ true ]; do head -n 100 /dev/urandom; sleep .1; done | hexdump -C | grep "ca fe"
for i in {0..600}; do echo $i; sleep 1; done | dialog --gauge "Install..." 6 40
2010-10-05 02:29:23
User: dennisw
Functions: echo sleep
9

Dialog's gauge widget accepts progress updates on stdin. This version runs dialog once and updates it every second.

There's no need to use timeout which causes screen flicker since it restarts dialog for each update.

rd(){ while read a ;do printf "$a\n";sleep ${1-1};done ;} # usage: rd < file ; or ... | rd
2010-10-03 04:16:03
User: argv
Functions: file printf read sleep
2

usage examples

ls largedir |rd

lynx -dump largewebsite.com |rd

rd < largelogfile

while :; do ping -W1 -c1 -n 8.8.8.8 > /dev/null || tput bel > /dev/console; sleep 1; done
2010-09-24 06:34:12
User: hackerb9
Functions: ping sleep tput
0

This is like ping -a, but it does the opposite. It alerts you if the network is down, not up. Note that the beep will be from the speaker on the server, not from your terminal.

Once a second, this script checks if the Internet is accessible and beeps if it is not. I define the Net as being "UP", if I can ping Google's public DNS server (8.8.8.8), but of course you could pick a different static IP address. I redirect the beep to /dev/console so that I can run this in the background from /etc/rc.local. Of course, doing that requires that the script is run by a UID or GID that has write permissions to /dev/console (usually only root).

Question: I am not sure if the -W1 flag works under BSD. I have only tested this under GNU/Linux using ping from iputils. If anybody knows how portable -W is, please post a comment.

sleep 4; F="$(tempfile -s '.xwd')"; xwd > "$F" ; gimp "$F"
for x in $(eselect bashcomp list | sed -e 's/ //g' | cut -d']' -f2 | sed -e 's/\*//');do eselect bashcomp enable $x --global;sleep 0.5s;done
2010-09-21 00:17:26
User: chronos
Functions: cut enable sed sleep
4

enable each bash completion that you have installed at your system, that's very nice ;)

sleep 4; xwd > /tmp/_.xwd ; gimp /tmp/_.xwd