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:

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

Let us make the script executable.

chmod +x ./´╗┐

Now you can run the script like this...


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

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