Commands using sleep (260)

  • This command will play back each keystroke in a session log recorded using the script command. You'll need to replace the ^[ ^G and ^M characters with CTRL-[, CTRL-G and CTRL-M. To do this you need to press CTRL-V CTRL-[ or CTRL-V CTRL-G or CTRL-V CTRL-M. You can adjust the playback typing speed by modifying the sleep. If you're not bothered about seeing each keypress then you could just use: cat session.log Show Sample Output

    (IFS=; sed 's/^[]0;[^^G]*^G/^M/g' <SessionLog> | while read -n 1 ITEM; do [ "$ITEM" = "^M" ] && ITEM=$'\n'; echo -ne "$ITEM"; sleep 0.05; done; echo)
    jgc · 2010-01-20 16:11:32 2
  • The '[r]' is to avoid grep from grepping itself. (interchange 'r' by the appropriate letter) Here is an example that I use a lot (as root or halt will not work): while (ps -ef | grep [w]get); do sleep 10; done; sleep 60; halt I add the 'sleep 60' command just in case something went wrong; so that I have time to cancel. Very useful if you are going to bed while downloading something and do not want your computer running all night.

    while (ps -ef | grep [r]unning_program_name); do sleep 10; done; command_to_execute
    m_a_xim · 2010-01-14 16:26:34 0
  • This is a more accurate way to watch the progress of a dd process. The $DDPID=$! is needed so that you don't get the PID of the sleep. The sleep 1 is needed because in my testing at least, if you run kill -USR1 against dd too quickly, it will kill it off instead of display the status. So you need to wait a second, probably so that it can configure itself to trap the USR1 signal. Show Sample Output

    dd if=fromfile of=tofile & DDPID=$! ; sleep 1 ; while kill -USR1 $DDPID ; do sleep 5; done
    deltaray · 2010-01-12 15:01:44 1
  • The following command will clone usb stick inside /dev/sdc to /dev/sdd Double check you got the correct usb sticks (origional-clone)with fdisk -l.

    dd if=/dev/sdc of=/dev/sdd conv=notrunc & while killall -USR1 dd; do sleep 5; done
    bw · 2010-01-12 14:09:40 3

  • 2
    p(){ printf "\033[%d;%dH\033[4%dm \033[m" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); }; clear;while :;do p; sleep .001;done
    cfajohnson · 2009-12-17 15:25:28 0
  • Displays a scrolling banner which loops until you hit Ctrl-C to terminate it. Make sure you finish your banner message with a space so it will loop nicely.

    while [ 1 ]; do banner 'ze missiles, zey are coming! ' | while IFS="\n" read l; do echo "$l"; sleep 0.01; done; done
    craigds · 2009-12-14 07:40:07 2
  • This command can be set as an alias in ~/.bashrc For example (in my case) I have : alias watchDl='while [ "$(ls $filePart)" != "" ]; do sleep 5; done; mpg123 /home/.../warning.mp3" ' Then I just need to - initialize filePart (e.g. filePart="*bigFile*rar.part") - launch watchDl

    while [ "$(ls $filePart)" != "" ]; do sleep 5; done; mpg123 /home/.../warning.mp3
    mrttlemonde · 2009-12-06 10:55:09 6
  • If the remote doesn't export its desktop (eg fluxbox, blackbox etc) then you need to run a x11vnc server there and a vncviewer at the local end. This command does the lot for you - it assumes that you can 'ssh' to the box without a password and that x11vnc is installed at the remote end.

    rdp() { ssh $1 sh -c 'PATH=$PATH:/usr/local/bin; x11vnc -q -rfbauth ~/.vnc/passwd -display :0' & sleep 4; vncviewer $1:0 & }
    bhepple · 2009-11-25 07:21:02 0
  • The above code is just an example of printing on the same line, hit Ctrl + C to stop When using echo -ne "something\r", echo will: - print "something" - dont print a new line (-n) - interpret \r as carriage return, going back to the start of the line (-e) Remember to print some white spaces after the output if your command will print lines of different sizes, mainly if one line will be smaller than the previous Edit from reading comments: You can achieve the same effect using printf (more standardized than echo): while true; do printf "%-80s\r" "$(date)"; sleep 1; done

    while true; do echo -ne "$(date)\r"; sleep 1; done
    polaco · 2009-11-17 22:45:37 4
  • Stops when the (last) dd process exits.

    while killall -USR1 dd; do sleep 5; done
    Mikachu · 2009-11-09 00:27:33 0
  • Strip my code to: wmctrl -o 0,0 # autorotates to the first face. In fact [0-1279],0 wmctrl - 1280,0 # goes to the second face wmctrl -o 2560,0 # goes to the third face, and so on. # Use multiples of the horizontal display resolution. My example work for 1280x800 display, been 1280 the number of interest. Tweak the number, try a biiiig one and see your cube spinning... I put a complex example to show how fun things can be, even for my ademco and paradox alarm central network advisor interface xpto etc. It rotates two faces, print the alarm message, and goes back tho where it was. Tested on BIGLINUX 4.2, equivalent to ubuntu LTS hardy. Do not forget to activate 3D efects ( compiz cube ) Show Sample Output

    wmctrl -o 2560,0 ;sleep 2 ; echo "FIRE 001" | osd_cat -o 470 -s 8 -c red -d 10 -f -*-bitstream\ vera\ sans-*-*-*--250-*-*-*-*-*-*-* ; sleep 1; wmctrl -o 0,0
    m33600 · 2009-10-23 10:00:51 0
  • This will record the Alexa Traffic Stats to a file and run every 5 hours. -- --

    x=1 ; while [ $x -le 10 ] ; do lynx -dump[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done &
    felix001 · 2009-10-17 13:48:05 0
  • Remounts a usb disk /dev/sdb, without having to physically remove and reinsert. (Gnome desktop)

    eject /dev/sdb; sleep 1; eject -t /dev/sdb
    Escher · 2009-10-11 23:16:49 3
  • Check out the usage of 'trap', you may not have seen this one much. This command provides a way to schedule commands at certain times by running them after sleep finishes sleeping. In the example 'sleep 2h' sleeps for 2 hours. What is cool about this command is that it uses the 'trap' builtin bash command to remove the SIGHUP trap that normally exits all processes started by the shell upon logout. The 'trap 1' command then restores the normal SIGHUP behaviour. It also uses the 'nice -n 19' command which causes the sleep process to be run with minimal CPU. Further, it runs all the commands within the 2nd parentheses in the background. This is sweet cuz you can fire off as many of these as you want. Very helpful for shell scripts.

    ( trap '' 1; ( nice -n 19 sleep 2h && command rm -v -rf /garbage/ &>/dev/null && trap 1 ) & )
    AskApache · 2009-10-10 04:43:44 1
  • Very useful for interactive scripts where you would like to return the terminal contents to its original state before the script was run. This would be similar to how vi exits and returns you to your original terminal screen. Save and clear the terminal contents with: tput smcup Execute some commands, then restore the saved terminal contents with: tput rmcup

    tput smcup; echo "Doing some things..."; sleep 2; tput rmcup
    jgc · 2009-10-08 16:48:04 2
  • Mostly for Norwegians, but easily adoptable to others. Very handy if you are brainstorming for a new domainname. Will only display the available ones.. You can usually do this better with dig, but if you dont have dig, or the TLD only have an online service to check with, this will be usefull.. Show Sample Output

    check_dns_no() { for i in $* ; do if `wget -O - -q$ | grep "no match" &>/dev/null` ; then echo $ "available" ; fi ; sleep 1 ;done }
    xeor · 2009-09-30 21:17:33 2
  • A little bash daemon

    echo "Starting Daemon"; ( while :; do sleep 15; echo "I am still running =]"; done ) & disown -h -ar $!
    tatsu · 2009-09-30 16:00:13 4
  • Log a command's votes, then run: gnuplot -persist <(echo "plot 'votes' with lines")

    while true; do curl -s | grep 'id="num-votes-' | sed 's;.*id="num-votes-[0-9]*">\([0-9\-]*\)</div>;\1;' >> votes; sleep 10; done
    matthewbauer · 2009-09-26 00:55:24 0

  • 23
    timeout 10 sleep 11
    syssyphus · 2009-09-23 14:59:40 7
  • Very useful in shell scripts because you can run a task nicely in the background using job-control and output progress until it completes. Here's an example of how I use it in backup scripts to run gpg in the background to encrypt an archive file (which I create in this same way). $! is the process ID of the last run command, which is saved here as the variable PI, then sleeper is called with the process id of the gpg task (PI), and sleeper is also specified to output : instead of the default . every 3 seconds instead of the default 1. So a shorter version would be sleeper $!; The wait is also used here, though it may not be needed on your system. echo ">>> ENCRYPTING SQL BACKUP" gpg --output archive.tgz.asc --encrypt archive.tgz 1>/dev/null & PI=$!; sleeper $PI ":" 3; wait $PI && rm archive.tgz &>/dev/null Previously to get around the $! not always being available, I would instead check for the existance of the process ID by checking if the directory /proc/$PID existed, but not everyone uses proc anymore. That version is currently the one at but I plan on upgrading to this new version soon. Show Sample Output

    sleeper(){ while `ps -p $1 &>/dev/null`; do echo -n "${2:-.}"; sleep ${3:-1}; done; }; export -f sleeper
    AskApache · 2009-09-21 07:36:25 1
  • This will log your internet download speed. You can run gnuplot -persist <(echo "plot 'bps' with lines") to get a graph of it.

    echo $(date +%s) > start-time; URL=; while true; do echo $(curl -L --w %{speed_download} -o/dev/null -s $URL) >> bps; sleep 10; done &
    matthewbauer · 2009-09-19 21:26:06 0
  • Get sopcast links for live sports from (for example) Get sp-sc or sp-auth binary by googling (sopcast + linux) eg Requires the 32bit libstdc++5 package. After exiting mplayer, type 'killall sp-sc'

    (sp-sc sop:// 3900 8900 &>/dev/null &); sleep 10; mplayer http://localhost:8900/tv.asf
    Escher · 2009-09-19 17:46:13 1
  • [Note: This command needs to be run as root]. If you are downloading something large at night, you can start wget as a normal user and issue the above command as root. When the download is done, the computer will automatically go to sleep. If at any time you feel the computer should not go to sleep automatically(like if you find the download still continuing in the morning), just create an empty file called nosleep in /tmp directory.

    while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem >/sys/power/state
    kamathln · 2009-09-06 05:51:20 0
  • Rainbow, instead of greys

    yes "$(seq 1 255)" | while read i; do printf "\x1b[48;5;${i}m\n"; sleep .01; done
    unixmonkey4581 · 2009-09-05 04:01:23 0
  • I wanted to keep a backup of my company database server on my local homeserver. After I found maatkit to sync databases, everything except security seemed fine. SSH takes care of that part.

    ssh -f -L3307: -N -t -x user@host sleep 600 ; mk-table-sync --execute --verbose u=root,p=xxx,h=,P=3307 u=root,p=xxx,h=localhost
    erlebnishengst · 2009-09-04 16:54:25 3
  • ‹ First  < 7 8 9 10 11 > 

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

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.


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: