sleep Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
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.
Options in sleep Command in Linux
-
--help: Displays help information for the sleep command.
For example -
Output:
This command displays the usage information and available options for the sleep command.
-
--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.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
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
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.