Linux Sleep Command Usage and Examples

This post will guide you how to use Sleep command from the command line on your Linux operating system. How do I use Sleep comand on a bash shell script.

Linux Sleep Command Usage and Examples1

Command NAME


sleep – delay for a specified amount of time

SYNOPSIS


sleep NUMBER[SUFFIX]...
sleep OPTION

DESCRIPTION


Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the default), ‘m’ for minutes, ‘h’ for hours or ‘d’ for days. Unlike most implementations that require NUMBER be an integer, here NUMBER may be an arbitrary floating point number. Given two or more arguments, pause for the amount of time specified by the sum of their values.

--help display this help and exit

--version output version information and exit

Linux Sleep Command Examples


If you want to delay for 20 seconds at the shell promt, type the following command:

$ sleep 20

If you want to delay for 1 hour, type:

$ sleep 1h

If you want to sleep for 15 minutes, type:

$ sleep 15m

You can also use Sleep command in a bash shell script, like below:

#!/bin/bash
echo -e "start to sleep 15 seconds......"
sleep 15
echo -e "continue to run program......"

Let’s run this shell script with the following command:

$ ./testSleep.sh

Outputs:

[email protected]:~$ ./testSleep.sh
start to sleep 15 seconds......
continue to run program......

 

You might also like:

Sidebar



back to top