Skip to main content

Module 4: Process Management

Lesson 41: sleep Command

In this lesson, you'll learn how to use the sleep command to delay command execution for a specified amount of time in Linux.

The sleep command is used to delay the next command execution. It causes the calling program to sleep for a specified amount of time.

So, let's learn more about the sleep command with practical examples in Linux.

sleep Command Syntax

The syntax of the sleep command is very simple, as it accepts one mandatory parameter with an optional suffix:

$ sleep <NUMBER>[SUFFIX]

It is important to note that, in the above syntax, there isn't a space between the NUMBER and SUFFIX.

sleep Command Options

Suffix Description
s Specify time units in seconds (default)
m Specify time units in minutes
h Specify time units in hours
d Specify time units in days

1. Delay Linux Command Execution

By default, the sleep command waits for a number of seconds. To understand this, let's print the current time before and after the sleep command.

For example, the following command waits for 5 seconds after printing the current time:

$ date '+%r'; sleep 5; date '+%r'
11:42:01 AM
11:42:06 AM

In this example, we have used a semicolon (;) to separate each command.

2. Make a Command Wait N Minutes

Optionally, the sleep command allows us to specify the time unit using suffixes.

So, let's use the m suffix to sleep for 1 minute:

$ date '+%r'; sleep 1m; date '+%r'
11:42:01 AM
11:43:01 AM

The important point to note is that there shouldn't be any space between NUMBER and SUFFIX.

3. Sleep for X Minutes and Seconds

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’