sleep Command in Linux with Examples

The sleep command, as the name suggests, pauses the execution of subsequent commands or scripts for a specified period. This delay facilitates various tasks, such as scheduling commands, managing script flow, or waiting during program execution.

The syntax for the sleep command in Linux is:

  • NUMBER: The number of seconds to sleep. This can be a decimal number.
  • SUFFIX: An optional suffix that specifies the unit of time. The following suffixes are available:
    • s: seconds (the default)
    • m: minutes
    • h: hours
    • d: days

Sleep Command Examples:

Example 1: Pause Execution for 3 Seconds

sleep 3

This command pauses the execution of the script for 3 seconds. After 3 seconds, the script will continue execution.


Example 2: Pausing for 5 minutes

sleep 5m

This command pauses the execution of the script for 5 minutes. After 5 minutes, the script will continue execution.

Example 3: Delay Execution for 2 Hours

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
sleep 2h

This command pauses the execution of the script for 2 hours. After 2 hours, the script will continue execution.

Example 4: Pause for 30 Seconds and 500 Milliseconds

sleep 30.5s

Using a decimal point allows specifying a duration with seconds and fractions of a second.


Example 5: Suspend Execution for 1 Hour, 15 Minutes, and 30 Seconds

sleep 1h15m30s

This command uses different time units (‘h’ for hours, ‘m’ for minutes, and ‘s’ for seconds) to create a precise delay of 1 hour, 15 minutes, and 30 seconds.

Example 6: Pause for 2 Days

sleep 2d

The ‘sleep’ command can also be used to halt execution for multiple days by specifying ‘d’ for days as the time unit.


Example 7: sleep Command Bash Script

echo "Hi, I'm sleeping for 5 seconds..."
sleep 5
echo "I'm awake Now."

This script first prints a message indicating that it’s going to sleep for 5 seconds, then pauses execution for 5 seconds using the sleep command, and finally prints a message indicating that it’s awake again.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.