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

by on February 9, 2011 · 2 comments· LAST UPDATED February 9, 2011

in

How do I pause for 5 seconds or 2 minutes in my bash shell script?

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

 
sleep NUMBER[SUFFIX]
 

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 mintus, use:
sleep 2m

sleep Command Bash Script Example

 
#!/bin/bash
echo "Hi, I'm sleeping for 5 seconds..."
sleep 5
echo "all Done."
 


If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 2 comments… read them below or add one }

1 droopy4u February 13, 2011 at 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

Reply

2 Nicholas February 14, 2011 at 1:17 am

Thanks, nice tip!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , ,

Previous Faq:

Next Faq: