A hacky approach using pv
:
$ yes | pv -SeL1 -s 5 > /dev/null
ETA 0:00:04
Or:
$ yes | pv -SL1 -F 'Resuming in %e' -s 5 > /dev/null
Resuming in ETA 0:00:04
pv
is normally used to give a progress bar for the I/O of some data stream. Here we're using the constant stream of the yes
command, but rate-limiting it to 1 byte per second (-L1
), and S
topping after the output has reached a s
ize of 5
bytes.
You can add more in there like the elapsed time, ETA as in clock time when it's expected to finish, or even a progress bar:
$ yes | pv -SpeL1 -s 5 > /dev/null
[===========> ] 20% ETA 0:00:04
Note that the duration won't be exactly 5 seconds (closer to 6 actually here with pv 1.6.6 in my tests).
Speaking of progress bar, you can also feed its output to zenity
(graphical) or diaglog
/whiptail
for an even fancier display:
yes | pv -SnL1 -s 5 2>&1 > /dev/null |
zenity --progress --auto-close --no-cancel \
--title 'Please wait...' --text 'Please wait...'

yes | pv -SnL1 -s 5 2>&1 > /dev/null |
whiptail --gauge 'Please wait...' 5 20 0

For a smoother progress, you can increase the rate to 10 bytes per second (and multiply the cut-off size by 10) while telling it to give you 10 updates per second:
yes | pv -SpeL10 -i0.1 -s 50 > /dev/null
yes | pv -SnL10 -i 0.1 -s 50 2>&1 > /dev/null |
whiptail --gauge 'Please wait...' 6 20 0