# Countdown Clock

MIN=10 && for i in \$(seq \$((\$MIN*60)) -1 1); do printf "\r%02d:%02d:%02d" \$((i/3600)) \$(( (i/60)%60)) \$((i%60)); sleep 1; done

0
2011-02-20 10:24:22

## 4 Alternatives + Submit Alt

• Simple countdown clock that should be quite portable across any Bourne-compatible shell. I used to teach for a living, and I would run this code when it was time for a break. Usually, I would set "MIN" to 15 for a 15-minute break. The computer would be connected to a projector, so this would be projected on screen, front and center, for all to see. Show Sample Output

12
MIN=1 && for i in \$(seq \$((\$MIN*60)) -1 1); do echo -n "\$i, "; sleep 1; done; echo -e "\n\nBOOOM! Time to start."
· 2010-06-20 15:19:12
• Countdown clock - Counts down from \$MIN minutes to zero. I let the date command do the maths. This version doesn't use seq. Show Sample Output

11
MIN=10;for ((i=MIN*60;i>=0;i--));do echo -ne "\r\$(date -d"0+\$i sec" +%H:%M:%S)";sleep 1;done
· 2011-02-20 11:56:28
• The biggest advantage over atoponce's nifty original is not killing the scrollback. Written assuming bash, but shouldn't be terribly difficult to port to other shells. S should be multiple spaces, but I can't get commandlinefu to save/show them properly, any help?

1
function countdown { case "\$1" in -s) shift;; *) set \$((\$1 * 60));; esac; local S=" "; for i in \$(seq "\$1" -1 1); do echo -ne "\$S\r \$i\r"; sleep 1; done; echo -e "\$S\rBOOM!"; }
· 2010-06-30 12:20:01
• I find the other timers are inaccurate. It takes some microseconds to perform the date function. Therefore, using date/time math to calculate the time for us results in millisecond accuracy. This is tailored to the BusyBox date function. May need to change things around for GNU date function. Show Sample Output

-1
let T=\$(date +%s)+3*60;while [ \$(date +%s) -le \$T ]; do let i=\$T-\$(date +%s); echo -ne "\r\$(date -d"0:0:\$i" +%H:%M:%S)"; sleep 0.3; done
· 2019-10-22 15:04:21

### What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

### What's this?

commandlinefu.com 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.