Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App

sleep Command in Linux with Examples

Last Updated : 19 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

sleep command is used to create a dummy job. A dummy job helps in delaying the execution. It takes time in seconds by default but a small suffix(s, m, h, d) can be added at the end to convert it into any other format. This command pauses the execution for an amount of time which is defined by NUMBER.

Syntax of `sleep` Command in Linux

sleep NUMBER[SUFFIX]...

Here,

"NUMBER" represents the time duration for which the command should sleep.

"SUFFIX" can be used to specify the unit of time (s for seconds, m for minutes, h for hours, etc.).

Note: If no suffix is provided, the default unit is seconds.

Options Available in sleep command:

`--help` Option in Sleep Command

It displays help information about sleep commands

`--version` Option in Sleep Command

It displays version information of the sleep command.

Examples of `sleep` Command in Linux

Basic Usage of `sleep` Command in Linux:

The simplest use of the Sleep command involves specifying the duration in seconds. For instance:

sleep 6


Basic Usage of sleep command
Basic Usage of Sleep Command


In this example, the Sleep command pauses the execution for 6 seconds. This is particularly useful in scripts where you need to introduce delays between commands or processes.

Using Suffixes in `sleep` Command in Linux:

Sleep allows you to specify time units using suffixes, providing flexibility in defining durations. Here's an example:

sleep 3m


Suffix `m` in Sleep Command
Suffix `m` in Sleep Command


In this case, the 'm' suffix denotes minutes. Therefore, the Sleep command will pause execution for 3 minutes. This is beneficial when you need more extended periods of delay, and using suffixes makes the command more human-readable.

Other suffixes include:

Suddixes

Description

's'

This is used for specifying seconds.

'h'

This is used for specifying hours.

'd'

This is used for specifying days.

For instance:

sleep 3h

This command sleeps for 3 hours.

Specifying Fractional Seconds in `sleep` Command in Linux

You can use decimal values to specify fractional seconds.

sleep 3.5


Fractional Seconds in `sleep` Command
Fractional Seconds in `Sleep` Command


This command sleeps for 3.5 seconds, allowing for more precise control over the sleep duration.

Interrupting Sleep:

The Sleep command can be interrupted using signals, such as pressing `Ctrl+C`, which sends a SIGINT signal, terminating the sleep:

sleep 12
# Press Ctrl+C after a few seconds to interrupt the sleep


Interrupting Sleep
Interrupting Sleep


This allows users to gracefully interrupt the sleep duration and proceed with other actions.

Bash Sleep Command

The Sleep command is like a pause button for your computer. You just type "sleep N," with N being a number (either a whole number or a number with decimals), and it makes your computer wait for that many seconds before doing the next thing in your script. It's that easy!

Let us understand this with an Example of a script.

We have this script :

#!/bin/bash
echo "Hello GeeksforGeeks!"
sleep 5
echo "Sleep for 5 seconds"


Bash Sleep Command
Bash Sleep Command


In this, we created the script using `vim`, then made our script executable `chmod +x`, then ran our script using `./example.sh`.

Conclusion

In this article, we discussed the `sleep` command in Linux which is a versatile tool for introducing delays in script execution. Its simple syntax, defined as `sleep NUMBER[SUFFIX]...`, allows users to easily specify time durations, either in seconds or with various suffixes denoting minutes, hours, or days. This article covered basic usage with examples like `sleep 6`, demonstrated the use of suffixes as in `sleep 3m`, and explored advanced options such as interrupting sleep with signals. The Bash `Sleep` Command serves as a pause button, enabling computers to wait for a specified duration before proceeding to the next task in a script. Overall, the sleep command proves essential in scripting, providing precise control over time delays and enhancing overall efficiency in Linux operations.


D

DrRoot_
Improve
Article Tags :
  • Technical Scripter
  • Linux-Unix
  • linux-command
  • Linux-Shell-Commands

Similar Reads

    scriptreplay command in Linux with Examples
    scriptreplay command is used to replay a typescript/terminal_activity stored in the log file that was recorded by the script command. With the help of timing information, the log files are played and the outputs are generated in the terminal with the same speed the original script was recorded. The
    3 min read
    sdiff command in Linux with Examples
    sdiff command in Linux is used to compare two files and then writes the results to standard output in a side-by-side format. It displays each line of the two files with a series of spaces between them if the lines are identical. It displays a greater than sign if the line only exists in the file spe
    3 min read
    Sed Command in Linux/Unix With Examples
    The SED command (short for Stream Editor) is one of the most powerful tools for text processing in Linux and Unix systems. It's commonly used for tasks like search and replace, text transformation, and stream editing.With SED, you can manipulate text files without opening them in an editor. This mak
    8 min read
    select command in Linux with examples
    select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of commands written in the select block and then asks again to enter a number, if a wrong option is entered it does nothing. If the user enters
    2 min read
    seq command in Linux with Examples
    The 'seq' command in Linux is a powerful utility used to generate a sequence of numbers. It is particularly useful in scenarios where you need to create a list of numbers within loops, such as while, for, or until loops. With 'seq', you can quickly generate numbers from a starting value (FIRST) to a
    4 min read
    setsid command in Linux with Examples
    setsid command in Linux system is used to run a program in a new session. The command will call the fork(2) if already a process group leader. Else, it will execute a program in the current process. The main advantage of using 'setsid' is that it allows programs to run independently of the terminal
    3 min read
    Shift command in Linux with examples
    Shift is a built-in command in bash that after getting executed, shifts/moves the command line arguments to one position left. The first argument is lost after using the shift command. This command takes only one integer as an argument. This command is useful when you want to get rid of the command
    3 min read
    showkey command in Linux with Examples
    showkey command in Linux is used to examine the codes sent by the keyboard. showkey prints to standard output either the scan codes or the key code or the 'ASCII' code of each key pressed. The program runs in the first two modes until 10 seconds have elapsed since the last key press or release event
    2 min read
    shred Command in Linux with Examples
    When you delete a file from Linux or from any Operating System, then the file is not deleted permanently from the hard disk. When a file is deleted, it first gets moved to the trash and as soon as you clear off the trash the files get deleted for the file system. But the file is still there on your
    6 min read
    shutdown command in Linux with Examples
    The `shutdown` operation in Linux is a crucial command for managing system power states, allowing administrators to halt safely, power off, or reboot the system. This command provides flexibility in scheduling downtimes, ensuring minimal disruption to users and processes. In this article, we will ex
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences