Table of Contents

Bash Sleep

In bash, we can use sleep command to add delay between commands.

Bash Wait Seconds

To sleep for 5 seconds, use:

sleep 5

Bash Wait Minutes

Want to sleep for 2 minutes, use:

sleep 2m

Shell Script Sleep

Put following in a file. Example: test_bash_script.sh

#!/bin/bash
##Sleep for 10 seconds every time the script goes through the loop and print count.
for i in {1..10}
do
  echo $i
  sleep 10s
done

Let us make the script executable.

chmod +x ./test_bash_script.sh

Now you can run the script like this...

./test_bash_script.sh

Shell Script Sleep ms

If you have GNU sleep, you can simply do following...

Sleep for 1 ms...

sleep 0.001

Otherwise you need to install the Bash with loadsleep. Checkout following link for more details...

https://serverfault.com/questions/469247/how-do-i-sleep-for-a-millisecond-in-bash-or-ksh/469249

Otherwise if you have NPM (Nodejs package manager installed), You can install following utility...

npm install sleep-ms --save;

Then you can run following command...

# sleep for 1 second
sleepms 1000;

Related Posts

1
2
3
4
5