≡ Menu

Linux / UNIX: Bash Script Sleep or Delay a Specified Amount of Time

How do I pause for 5 seconds or 2 minutes in my bash shell script on a Linux or Unix-like systems?

You need to use the sleep command to add delay for a specified amount of time. The syntax is as follows for gnu/bash sleep command:


Where SUFFIX may be:

  1. s for seconds (the default)
  2. m for minutes.
  3. h for hours.
  4. d for days.

To sleep for 5 seconds, use:
sleep 5
To sleep for 2 minutes, use:
sleep 2m
To sleep for 3 hours, use:
sleep 3h
To sleep for 5 days, use:
sleep 5d
The most common usage are as follows:

## run commmand1, sleep for 1 minute and finally run command2 ## 
command1 && sleep 1m && command2
## sleep in bash for loop ##
for i in {1..10}
  sleep 5s
## run while loop to display date and hostname on screen ##
while [ : ]
    tput cup 5 5
    tput cup 6 5
    echo "Hostname : $(hostname)"
    sleep 1

Sample outputs from last while loop:

Animated gif.01: Sleep command in action

Animated gif.01: Sleep command in action

sleep Command Bash Script Example

Here is a simple example:

echo "Hi, I'm sleeping for 5 seconds..."
sleep 5  
echo "all Done."

In this example, create the lock directory. I’m using [/\\:.-] here to ensure that we don’t use the same name that we are using for the .o file. Also, base the name on the expected object file name, since that is what matters with a parallel build.

lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
  if mkdir "$lockdir" >/dev/null 2>&1; then
  sleep 1
Share this tutorial on:
{ 10 comments… add one }
  • droopy4uFebruary 13, 2011, 2:41 pm

    with the command ‘sleep’ , for more information use the manual pages of sleep by ‘man sleep’.

    sleep 5s ; echo ‘end test sleep 5sec’
    sleep 1m; echo ‘end test sleep 1min’

    best regards

  • NicholasFebruary 14, 2011, 1:17 am

    Thanks, nice tip!

  • Terry McCallAugust 20, 2013, 5:39 pm

    FYI for searchers who are OSX users:

    The sleep command in OSX does NOT take any suffix arguments (m/h/d). It only takes arguments in seconds.

    • ckJanuary 8, 2015, 6:58 pm

      FYI for searchers who are Android users:
      Drop the suffix, it goes by seconds:
      Sleep 3

  • testFebruary 21, 2014, 10:13 am


  • SergDecember 27, 2015, 8:54 am

    There is two types of sleep command – a shell built in and the /bin/seep. Both bash built-in and /bin/sleep take the suffixes, however the built in for mksh (which is on android) does not take suffixes. It’s is the same distinction between /usr/bin/time and shell built-in time

  • robertJanuary 30, 2016, 8:56 am

    You have an excellect display of quick and simple scripts.
    Thank you,

  • Bruno VernaySeptember 11, 2016, 6:39 pm

    watch also would be handy:
    watch runs command repeatedly, displaying its output and errors (the first screenfull). This allows you to watch the program output change over time. By default, the program is run every 2 seconds. By default, watch will run until interrupted.

  • remcoSeptember 17, 2016, 11:11 am


    How i can make a script for my centos7 server dat shutdown my server on 0:00 and boot it at 12:00 ?


    • testOctober 11, 2016, 11:08 am

      you can’t

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , ,