sleep Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The sleep command in Linux is a command-line utility that allows you to insert a delay in the execution of a script or a command. It's an essential tool for scripting and automation, providing control over when certain operations happen. The sleep command in Linux takes a time duration as an argument and pauses the execution of the next command for the specified time period.

Syntax of sleep Command in Linux

The basic syntax of the sleep command in Linux is as follows:

Where:

  • NUMBER: This is the numeric value that defines the duration of the delay. It can be any number, including a decimal.
  • SUFFIX: This optional part of the syntax defines the unit of time for the delay. It can be 's' for seconds, 'm' for minutes, 'h' for hours, or 'd' for days. If no suffix is provided, the sleep command in Linux assumes seconds by default.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in sleep Command in Linux

  1. --help: Displays help information for the sleep command.

    For example -

    Output:

    This command displays the usage information and available options for the sleep command.

  2. --version: Displays the version information of the sleep command.

    For example -

    Output:

    This command displays the version of the sleep utility installed on your system.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of sleep Command with seconds.:

    Output:

    Explanation: The command delays the next operation for 5 seconds.

  • Using sleep command with minutes.:

    Output:

    Explanation: The command pauses the next operation for 2 minutes.

Tips

  • The sleep command in Linux can be combined with other commands using the semicolon (;) or the logical AND (&&) operator.

  • The sleep command is particularly useful in bash scripting for delaying the execution of the next command.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of sleep Command in Linux

  • Combining sleep with other commands using the semicolon (;).:

    Output:

    Explanation: This command prints 'Starting', waits for 3 seconds, and then prints 'Finished'.

  • Using sleep in a bash loop.:

    Output:

    Explanation: This command counts from 1 to 5, with a delay of 1 second between each number.

  • Delaying the execution of a bash script using sleep.:

    Output:

    Explanation: This command demonstrates how to delay a script's execution by 2 hours using the sleep command in Linux.

Conclusion

  • The sleep command in Linux is a simple yet powerful tool for introducing delays in the execution of commands and scripts.

  • Sleep takes a numerical argument followed by an optional suffix which can be 's' for seconds, 'm' for minutes, 'h' for hours, and 'd' for days.

  • Sleep can be combined with other commands to control the flow of execution.