How can I display a real-time countdown timer on the Linux terminal? Is there an existing app or, even better, a one liner to do this?


35 Answers 35


I'm not sure why you need beep. If all you want is a stopwatch, you can do this:

while true; do printf '%s\r' "$(date)"; done

That will show you the seconds passing in realtime and you can stop it with Ctrl+C. If you need greater precision, you can use this to give you nanoseconds:

while true; do printf '%s\r' "$(date +%H:%M:%S:%N)"; done

Finally, if you really, really want "stopwatch format", where everything starts at 0 and starts growing, you could do something like this:

start=$(date +%s)
while true; do
    time="$(($(date +%s) - $start))"
    printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"

For a countdown timer (which is not what your original question asked for) you could do this (change seconds accordingly):

start="$(($(date +%s) + $seconds))"
while [ "$start" -ge `date +%s` ]; do
    time="$(( $start - `date +%s` ))"
    printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"

You can combine these into simple commands by using bash (or whichever shell you prefer) functions. In bash, add these lines to your ~/.bashrc (the sleep 0.1 will make the system wait for 1/10th of a second between each run so you don't spam your CPU):

countdown() {
    start="$(( $(date '+%s') + $1))"
    while [ $start -ge $(date +%s) ]; do
        time="$(( $start - $(date +%s) ))"
        printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
        sleep 0.1

stopwatch() {
    start=$(date +%s)
    while true; do
        time="$(( $(date +%s) - $start))"
        printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)"
        sleep 0.1

You can then start a countdown timer of one minute by running:

countdown 60

You can countdown two hours with:

countdown "$((2 * 60 * 60))"

or a whole day using:

countdown "$((24 * 60 * 60))"

And start the stopwatch by running:


If you need to be able to deal with days as well as hours, minutes and seconds, you could do something like this:

countdown() {
    start="$(( $(date +%s) + $1))"
    while [ "$start" -ge $(date +%s) ]; do
        ## Is this more than 24h away?
        days="$(($(($(( $start - $(date +%s) )) * 1 )) / 86400))"
        time="$(( $start - `date +%s` ))"
        printf '%s day(s) and %s\r' "$days" "$(date -u -d "@$time" +%H:%M:%S)"
        sleep 0.1

stopwatch() {
    start=$(date +%s)
    while true; do
        days="$(($(( $(date +%s) - $start )) / 86400))"
        time="$(( $(date +%s) - $start ))"
        printf '%s day(s) and %s\r' "$days" "$(date -u -d "@$time" +%H:%M:%S)"
        sleep 0.1

Note that the stopwatch function hasn't been tested for days since I didn't really want to wait 24 hours for it. It should work, but please let me know if it doesn't.

  • 12
    I added these nice functions to my .zshrc right after I read your answer. Today I used countdown the first time and noticed a rather high CPU usage. I added a sleep 0.1 (I don't know if a sleep time of a fractional second is supported on all systems) which improved that a lot. The drawback is of course a less accurate display accuracy, but I can live with a deviation of max. 100ms.
    – mpy
    Jul 5, 2013 at 14:45
  • 5
    Just found this answer. I found putting the carriage return at the beginning of the echo statement in the stopwatch function was handy as it meant killing the stopwatch didn't overwrite the current stopwatch time: echo -ne "\r$(date -u --date @$((date +%s - $date1)) +%H:%M:%S)";
    – mkingston
    Jun 16, 2014 at 12:51
  • 2
    @chishaku yes, the OSX date command doesn't have the -d option. Well, it does, but it's for something else. You might be able to do something with -v but I don't have a mac (or access to BSD find) so I can't really help.
    – terdon
    Sep 29, 2014 at 18:05
  • 3
    @chishaku: On OS X, this seemed to work for me: echo -ne "$(date -ju -f %s $(($date1 - date +%s)) +%H:%M:%S)\r"; Jul 11, 2016 at 16:26
  • 1
    With sox package I would add a nice sound to play at the end of the countdown: play -q -n synth 2 pluck C5.
    – Pablo A
    May 15, 2018 at 23:59

My favorite way is:


time cat



As @wjandrea commented below, another version is to run:

time read

and press Enter to stop

  • 18
    similar, but you can press Enter to stop it: time read
    – wjandrea
    May 25, 2016 at 1:07
  • 22
    time read fails in zsh, but time (read) works.
    – Sparhawk
    Oct 7, 2016 at 4:53
  • 5
    Problem is though, that you cannot see the time without canceling it or finishing it. When you then restart it, the timer begins anew. Oct 18, 2017 at 8:50

I was looking for the same thing and ended up writing something more elaborate in Python:

This will give you a simple 10-second countdown:

pip install termdown
termdown 10

Source: https://github.com/trehn/termdown

  • doesn't work with python 3.x
    – Suhaib
    Jun 20, 2014 at 2:18
  • 3
    @Suhaib: It should and does for me. Please raise an issue on GitHub with more info.
    – trehn
    Jun 27, 2014 at 9:23
  • 1
    needs a brew package
    – chovy
    Sep 13, 2021 at 10:37
  • Much better answer than the accepted one for me, since the accepted answer uses a lot of CPU resources for a countdown. This one doesn't.
    – C26
    Nov 10, 2021 at 12:27
  • Do not use sudo pip install under any circumstances. You are liable to break your system's Python installation. If this tool is not available in your preferred package repo, use Pipx to install "standalone" Python applications, or at least use pip install --user. Jan 27, 2022 at 5:39

Use leave (it at least works on BSD descendants):

man leave

Set a timer for 15 minutes:

leave +0015
Alarm set for Thu Nov  3 14:19:31 CDT 2016. (pid 94317)
  • 3
    leave works in Linux too, but first you have to install the leave program from the default repositories.
    – karel
    Nov 4, 2016 at 4:10
  • 5
    leave does the job on mac and produces beep sound
    – Dmitry
    Jan 9, 2020 at 18:14
  • 2
    it is nice, except currently it doesn't do seconds, so it is not possible to count down 30 seconds, for example Dec 4, 2020 at 10:56
  • 1
    Its a little weird, but works. Though I use at so it sends me a notify message: at now + 4 minutes <<EOF notify-send tea EOF. Just add newlines.
    – Yarek T
    Jun 9, 2023 at 13:29

Short answer:

for i in `seq 60 -1 1` ; do echo -ne "\r$i " ; sleep 1 ; done


I know there are a lot of answers, but I just want to post something very close to OP's question, that personally I would accept as indeed "oneliner countdown in terminal". My goals were:

  1. One liner.
  2. Countdown.
  3. Easy to remember and type in console (no functions and heavy logic, bash only).
  4. Does not require additional software to install (can be used on any server I go via ssh, even if I do not have root there).

How it works:

  1. seq prints numbers from 60 to 1.
  2. echo -ne "\r$i " returns caret to beginning of the string and prints current $i value. Space after it is required to overwrite previous value, if it was longer by characters than current $i (10 -> 9).
  • 2
    This worked best for my use case on Mac OS for use in a bash script. The explanation of how it works is extra helpful.
    – james-see
    Aug 12, 2019 at 17:56
  • Other useful side effect: if the system is sent to standby, the timer is not (meaningfully) impacted.
    – Marcus
    May 1, 2023 at 8:06

I've used this one:

  set -- $*
  secs=$(( ${1#0} * 3600 + ${2#0} * 60 + ${3#0} ))
  while [ $secs -gt 0 ]
    sleep 1 &
    printf "\r%02d:%02d:%02d" $((secs/3600)) $(( (secs/60)%60)) $((secs%60))
    secs=$(( $secs - 1 ))


 countdown "00:07:55"

Here's a source.

  • 3
    POSIX compliant - works on OS X :)
    – Jules
    Feb 24, 2015 at 1:02
  • error on arch linux: countdown:4: bad math expression: operand expected at `* 60 + '
    – Chalist
    Dec 18, 2019 at 1:03
  • @Chalist could it be that you are using Zsh. Worked well on Bash Dec 6, 2020 at 20:47
  • Note that this solution is not 100% accurate: it assumes that "sleep 1 & printf" runs exactly 1 second every time, which is never true. If your system is too busy, your timer will be slow. Due to relativistic effects.
    – kolypto
    Aug 16, 2021 at 15:36

Another approach

countdown=60 now=$(date +%s) watch -tpn1 echo '$((now-$(date +%s)+countdown))'

For Mac:

countdown=60 now=$(date +%s) watch -tn1 echo '$((now-$(date +%s)+countdown))'
#no p option on mac for watch

If one wants a signal when it hits zero, one could e.g. build it with a command that returned a non-zero exit status at zero and combine it with watch -b, or something, but if one wants to build a more elaborate script, this is probably not the way to go; it is more of a "quick and dirty one-liner" type solution.

I like the watch program in general. I first saw it after I had already written countless while sleep 5; do loops to different effects. watch was demonstrably nicer.


sw is a simple stopwatch that will run forever.



wget -q -O - http://git.io/sinister | sh -s -- -u https://raw.githubusercontent.com/coryfklein/sw/master/sw


 - start a stopwatch from 0, save start time in ~/.sw
sw [-r|--resume]
 - start a stopwatch from the last saved start time (or current time if no last saved start time exists)
 - "-r" stands for --resume
  • error on arch: Try 'date --help' for more information. ate: invalid option -- 'v'
    – Chalist
    Dec 18, 2019 at 1:12
  • Why would install something whose URL contains "sinister"? - "2. Evil or seemingly evil; indicating lurking danger or harm." Mar 7, 2020 at 18:06
  • 1
    I agree, “sinister” was a horrible name choice for a software installer.
    – Cory Klein
    Mar 7, 2020 at 20:56

I use this small Go program:

package main

import (

func format(d time.Duration) string {
   mil := d.Milliseconds() % 1000
   sec := int(d.Seconds()) % 60
   min := int(d.Minutes())
   return fmt.Sprintf("%v m %02v s %03v ms", min, sec, mil)

func main() {
   t := time.Now()
   for {
      time.Sleep(10 * time.Millisecond)
      s := format(time.Since(t))
      fmt.Print("\r", s)



I have combined terdon's very good answer, into a function which at the same time displays the time since the start, and the time till the end. There are also three variants, so it's easier to call (you don't have to do Bash math), and it's also abstracted.

Example of use:

{ ~ }  » time_minutes 15
Counting to 15 minutes
Start at 11:55:34     Will finish at 12:10:34
     Since start: 00:00:08     Till end:  00:14:51

And something like a work timer:

{ ~ }  » time_hours 8
Counting to 8 hours
Start at 11:59:35   Will finish at 19:59:35
     Since start: 00:32:41     Till end:  07:27:19

And if you need some very specific time:

{ ~ }  » time_flexible 3:23:00
Counting to 3:23:00 hours
Start at 12:35:11   Will finish at 15:58:11
     Since start: 00:00:14     Till end:  03:22:46

Here's the code to put into your .bashrc

function time_func()
   date2=$((`date +%s` + $1));
   date1=`date +%s`;
   date_finish="$(date --date @$(($date2)) +%T )"

   echo "Start at `date +%T`   Will finish at $date_finish"

    while [ "$date2" -ne `date +%s` ]; do
     echo -ne "     Since start: $(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)     Till end:  $(date -u --date @$(($date2 - `date +%s`)) +%H:%M:%S)\r";
     sleep 1

    printf "\nTimer finished!\n"
    play_sound ~/finished.wav

function time_seconds()
  echo "Counting to $1 seconds"
  time_func $1

function time_minutes()
  echo "Counting to $1 minutes"
  time_func $1*60

function time_hours()
  echo "Counting to $1 hours"
  time_func $1*60*60

function time_flexible()  # Accepts flexible input hh:mm:ss
    echo "Counting to $1"
    secs=$(time2seconds $1)
    time_func $secs

function play_sound()  # Adjust to your system
    cat $1 > /dev/dsp

function time2seconds() # Changes hh:mm:ss to seconds. Found in some other Stack Exchange answer
    a=( ${1//:/ }) 
    echo $((${a[0]}*3600+${a[1]}*60+${a[2]})) 

Combine this with some way of playing sound in linux terminal (Play MP3 or WAV file via the Linux command line) or Cygwin (cat /path/foo.wav > /dev/dsp works for me in Babun/Windows 7) and you have a simple flexible timer with alarm!


I'm surprised that nobody used the sleepenh tool in their scripts. Instead, the proposed solutions either use a sleep 1 between subsequent timer outputs or a busy loop that outputs as fast as possible. The former is inadequate because due to the small time spent doing the printing, the output will not actually happen once per second but a bit less than that which is suboptimal. After enough time passed, the counter will skip a second. The latter is inadequate because it keeps the CPU busy for no good reason.

The tool that I have in my $PATH looks like this:

if [ $# -eq 0 ]; then
    TIMESTAMP=$(sleepenh 0)
    before=$(date +%s)
    while true; do
        diff=$(($(date +%s) - before))
        printf "%02d:%02d:%02d\r" $((diff/3600)) $(((diff%3600)/60)) $((diff%60))
        TIMESTAMP=$(sleepenh $TIMESTAMP 1.0);
    exit 1 # this should never be reached
echo "counting up to $@"
"$0" &
trap "exit" INT TERM
trap "kill 0" EXIT
sleep "$@"
kill $counterpid

The script can either be used as a stop watch (counting up until interrupted) or as a timer that runs for the specified amount of time. Since the sleep command is used, this script allows to specify the duration for which to count in the same precision as your sleep allows. On Debian and derivatives, this includes sub-second sleeps and a nice human-readable way to specify the time. So for example you can say:

$ time countdown 2m 4.6s
countdown 2m 4.6s  0.00s user 0.00s system 0% cpu 2:04.60 total

And as you can see, the command ran exactly for 2 minutes and 4.6 seconds without much magic in the script itself.


The sleepenh tool comes from the package of the same name in Debian and its derivatives like Ubuntu. For distributions that don't have it, it comes from https://github.com/nsc-deb/sleepenh

The advantage of sleepenh is, that it is able to take into account the small delay that accumulates over time from the processing of other things than the sleep during a loop. Even if one would just sleep 1 in a loop 10 times, the overall execution would take a bit more than 10 seconds because of the small overhead that comes from executing sleep and iterating the loop. This error slowly accumulates and would over time make our stopwatch timer more and more imprecise. To fix this problem, one must each loop iteration compute the precise time to sleep which is usually slightly less than a second (for one second interval timers). The sleepenh tool does this for you.

  • I don't understand what benefit this gives over my answer which also uses sleep 0.1. What is sleepnh (I can't find it in the Arch repos) and how does it differ from sleep? As far as I can tell, you're basically doing the same thing as my answer above. What am I missing?
    – terdon
    Jan 26, 2017 at 12:28
  • @terdon Sleepenh comes from here github.com/nsc-deb/sleepenh The problem with just saying sleep 5 is, that you don't sleep for exactly 5 seconds. Try for example time sleep 5 and you see that running the command takes slightly more than 5 seconds. Over time the errors accumulate. The sleepenh utility allows to easily avoid this accumulation of error.
    – josch
    Jan 27, 2017 at 8:04
  • OK. On my system I see an error of 0.002 seconds. I really doubt anyone would use this sort of tool and expect better than millisecond accuracy, but it would be better if you at least edit your answer and i) explain why sleepnh is better than sleep (you only say other answers use sleep 1—which they don't, only the OP uses that) and ii) where to get it and how to install it since it isn't a standard tool.
    – terdon
    Jan 27, 2017 at 13:12
  • 1
    @terdon I explained the difference between sleep and sleepenh in the first paragraph. Anyways, I probably wasn't clear enough on that so I expanded more on that at the end. The millisecond accuracy problems is what you get when calling sleep once. They accumulate over time and at some point it's noticable. I did not say that others only use sleep 1. I said that they use sleep 1 or a busyloop. Which they still do. Show me a counter example. Answers that do sleep 0.1 are the same as those doing sleep 1 except that they accumulate errors even faster.
    – josch
    Jan 28, 2017 at 6:49
  • I came down the answers looking for someone at least acknowledging the existence of the problem you solved.
    – mariotomo
    Feb 20, 2018 at 14:11

I ended up writing my own shell script: GitHub gist

# script to create timer in terminal
# Jason Atwood
# 2013/6/22

# Start up
echo "starting timer script ..."
sleep 1 # seconds

# Get input from user
read -p "Timer for how many minutes?" -e DURATION
DURATION=$(( $DURATION*60 )) # convert minutes to seconds

# Get start time
START=$(date +%s)

# Infinite loop
while [ -1 ]; do
clear # Clear window

# Do math
NOW=$(date +%s)    # Get time now in seconds
DIF=$(( $NOW-$START ))    # Compute diff in seconds
ELAPSE=$(( $DURATION-$DIF ))    # Compute elapsed time in seconds
MINS=$(( $ELAPSE/60 ))    # Convert to minutes... (dumps remainder from division)
SECS=$(( $ELAPSE - ($MINS*60) )) # ... and seconds

# Conditional
if [ $MINS == 0 ] && [ $SECS == 0 ]    # if mins = 0 and secs = 0 (i.e. if time expired)
then # Blink screen
for i in `seq 1 180`; # for i = 1:180 (i.e. 180 seconds)
clear # Flash on
setterm -term linux -back red -fore white # use setterm to change background color
echo "00:00 " # extra tabs for visibility

sleep 0.5

clear # Flash off
setterm -term linux -default # Clear setterm changes from above
echo "00:00" # (I.e. go back to white text on black background)
sleep 0.5
done # End for loop
break    # End script

else # Else, time is not expired
echo "$MINS:$SECS"    # Display time
sleep 1 # Sleep 1 second
fi    # End if
done    # End while loop
  • 1
    Nice script, +1. Just so you know, that is a countdown timer, not a stopwatch.
    – terdon
    Jun 25, 2013 at 12:17
  • ha you're right, thats what I really wanted. I'll update my naming.
    – tir38
    Jun 26, 2013 at 17:31

Take a look at TermTime. It's a nice terminal based clock and stopwatch:

pip install termtime

For future reference, there is a command line tool called µTimer with very straightforward command line options for a countdown/count-up timer.


just a one liner

N=100; while [[ $((--N)) >  0 ]]; do  echo  $N |  figlet -c && sleep 1 ; done


enter image description here

Also we can clear the screen ( Terminal ) using ANSI Escape sequences using 2J format.

N=100; while [[ $((--N)) >  0 ]]; do  echo -e "\033[2J\033[0m"; echo "$N" |  figlet -c && sleep 1 ; done


installing figlet command is required if you need in BIG font, otherwise remove figlet part.

N=100; while [[ $((--N)) >  0 ]]; do  echo  $N  && sleep 1 ; done

and you can make to have a beautiful output using lolcat ...

N=100; while [[ $((--N)) >  0 ]]; do  echo "$N" |  figlet -c | lolcat &&  sleep 1 ; done


enter image description here


If you have pv installed, you can use the following one-liner to display a countdown timer and sleep for a minute (or any other amount of time, just change 60 to the desired number of seconds):

cat /dev/zero | pv -B 1 -L 1 -tpe -s 60 -S > /dev/null

You can also put it in a function:

sleep_with_progress() {
  cat /dev/zero | pv -B 1 -L 1 -tpe -s "$1" -S > /dev/null

# If you prefer a simpler output with just the countdown:
sleep_with_countdown() {
  cat /dev/zero | pv -B 1 -L 1 -e -s "$1" -S > /dev/null

Sample outputs taken at 5 seconds after starting:

user@host:~ $ sleep_with_progress 60
0:00:05 [===>                                                  ]  8% ETA 0:00:55
user@host:~ $ sleep_with_countdown 60
ETA 0:00:55


cat /dev/zero produces an infinite amount of ASCII zero (\0) characters. pv displays progress, rate limits the data flowing through it and terminates after 60 characters (details below). Finally, the redirection to /dev/null makes sure that the \0 characters are not sent to the terminal.

The parameters used for pv are:

  • -B 1 sets the buffer size to 1.
  • -L 1 rate limits the pipe to 1 character per second.
  • -tpe turns on the display of the time, progress and ETA indicators (while -e only shows the latter).
  • -s 60 specifies that pv should expect 60 bytes.
  • -S tells pv to stop after reaching the specified size even though the input continues (it is infinite).

Simply use watch + date in UTC time. You can also install some package for big display...

export now="`date +%s -u`";
watch -n 0,1 'date +%T -u -d @$((`date +%s` - $now ))'

#Big plain characters
watch -n 0,1 'date +%T -u -d @$((`date +%s` - $now )) | toilet -f mono12'

#Big empty charaters
watch -n 0,1 'date +%T -u -d @$((`date +%s` - $now )) | figlet -c -f big'

Try it!

See also http://www.cyberciti.biz/faq/create-large-colorful-text-banner-on-screen/


A Python example:


def stopwatch ( atom = .01 ):
    import time, sys, math

    start = time.time()
    last = start
    sleep = atom/2
    fmt = "\r%%.%sfs" % (int(abs(round(math.log(atom,10))))  if atom<1 else "")
    while True:
        curr = time.time()
        subatom = (curr-last)
        if subatom>atom:
            # sys.stdout.write( "\r%.2fs" % (curr-start))
            sys.stdout.write( fmt % (curr-start))
            last = curr




Pretend you are a person on OS X looking for a command line stopwatch. Pretend that you don't want to install the gnu tools and just want to run with the Unix date.

In that case do as terdon says, but with this modification:

function stopwatch(){
    date1=`date +%s`;
    while true; do
        echo -ne "$(date -jf "%s" $((`date +%s` - $date1)) +%H:%M:%S)\r";
        sleep 0.1
  • 1
    I tried it on OS X El Capitan, for some reason it is starting with 16:00:00 Oct 29, 2015 at 2:34
  • ok, I found the answer. It is to use date -ujf instead of date -jf and it will begin with 00:00:00 Dec 4, 2020 at 18:20

If your system already has Ruby, you can use:

#!/usr/bin/env ruby

n = ARGV[0].to_f
go_beginning_of_line = "\033[G"
clear_till_end_of_line = "\033[K"

time_end = Time.now + n
while Time.now < time_end
    more = time_end - Time.now
    print "#{go_beginning_of_line}Counting down #{more.round(1)} of #{n} seconds#{clear_till_end_of_line}"
    sleep [0.1, more].min
puts "#{go_beginning_of_line}Counting down #{n} seconds. \a\aDone.#{clear_till_end_of_line}"

This is a terminal based timer: https://github.com/naa-7/terminal_work_timer

timer counting down timer stopped


Simple one liner to do the countdown job:

cnt=10;until [ $cnt -eq 0 ]; do printf "\rYour Quiz will start in $cnt seconds.... ";sleep 1;cnt=$(expr $cnt - 1);done;echo;

This one liner is taken from my open source project called Automated_Quiz, which is hosted here : https://sourceforge.net/projects/automated-quiz/

For Stopwatch :

Paste the following three lines one by one on the terminal and press enter. Press Ctrl+c on the second line to exit the stopwatch, as required.

function stopwatch() {  cntd=$1; printf '%dd:%dh:%dm:%ds\n' $((cntd/86400)) $((cntd%86400/3600)) $((cntd%3600/60)) $((cntd%60)) ; };

cnt=0;while true; do printf "\rStopwatch : $cnt seconds";export var=$cnt;sleep 1;cnt=$(expr $cnt + 1);done;echo;

stopwatch $var
  • 2
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 13, 2021 at 7:16

I'd like to suggest "timer" for a large countdown clock. It's similar to termdown but it's written in Rust and provides a nice beep at the end.

timer demo


timer 11:00
timer 25min


cargo install timer_core

Source: https://github.com/pando85/timer


Found this question earlier today, when looking for a term application to display a large countdown timer for a workshop. None of the suggestions was exactly what I needed, so I quickly put another one together in Go: https://github.com/bnaucler/cdown

As the question is already sufficiently answered, consider this to be for the sake of posterity.


$ sleep 1500 && xterm -fg yellow -g 240x80 &

When that big terminal with yellow text jumps up, time to get up and stretch!

Notes: - 1500 seconds = 25 minute pomodoro - 240x80 = terminal size with 240 character row, and 80 rows. Fills up a screen for me noticeably.

Credit: http://www.linuxquestions.org/questions/linux-newbie-8/countdown-timer-for-linux-949463/

  • But it doesn't display anything until it reaches zero. The question contained "display a real-time countdown timer". Mar 7, 2020 at 18:04

A GUI version of the stopwatch

date1=`date +%s`
date1_f=`date +%H:%M:%S____%d/%m`
  while true; do 
    date2=$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)
    echo "# started at $date1_f \n$date2"
) |
zenity --progress \
  --title="Stop Watch" \
  --text="Stop Watch..." \

This is similar to the accepted answer, but terdon's countdown() gave me syntax errors. This one works great for me, though:

function timer() { 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\rTime's up!"; }

You can put it in .bashrc and then execute with: timer t (where t is time in minutes).


Another option under the "existing app" category: peaclock. Displays a "large" stopwatch, timer, or clock in the terminal. Quite a few key bindings facilitate interactive use.


A slightly shorter Python (3) example:

import sys
import time
from datetime import datetime
from datetime import timedelta

start = time.time() * 1000
while True:
        now = time.time() * 1000
        elapsed = now - start
        out = str(timedelta(milliseconds=elapsed))
        print(out + "\033[?25l", end='\r')
    except KeyboardInterrupt:
        print(out + '\033[?25h', end='\n')

Hides / restores blinking cursor. Control-c to quit.


I added a progress bar to and unlied the variable names in terdon's answer:

countdown() {                                                                   
  stop="$(( $(date '+%s') + $1))"                                               
  term_width=$(tput cols)                                                       
  while [ $stop -ge $(date +%s) ]; do                                           
    delta="$(( $stop - $(date +%s) ))"                                          
    complete_percent=$(( 100 - ($delta * 100) / $1))                            
    bar_width=$(($complete_percent * ($term_width - $counter_width) / 100))     
    printf '\r'                                                                 
    printf '%s ' "$(date -u -d "@$delta" +%H:%M:%S)"                            
    printf '%0.s-' $(seq 1 $bar_width)                                          
    sleep 0.5                                                                   
  printf '\n'                                                                   

It outputs something like:

00:00:05 --------------------

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .