
The 'sleep' command is a versatile tool for introducing delays in script execution. It is available in Unix, Unix-like and other operating systems, including Linux. The command suspends the calling process for a specified time, which can be in seconds, minutes, hours or days. It is particularly useful in scripts where delays between commands or processes are required. The syntax is simple: 'sleep NUMBER [SUFFIX]', where the suffix can be used to specify the unit of time. For example, 'sleep 6' or 'sleep 3m'. The sleep command can be interrupted using signals, such as pressing 'Ctrl+C'.
| Characteristics | Values |
|---|---|
| Operating Systems | Unix, Unix-like, Linux, IBM i, Microsoft Windows, OS-9 shell, KolibriOS Shell, FreeDOS Package group Utilities, MSX-DOS2 Tools for MSX-DOS version 2, and PowerShell |
| Purpose | To suspend program execution for a specified time |
| Syntax | sleep NUMBER [SUFFIX] |
| Default Unit | Seconds |
| Suffixes | s for seconds, m for minutes, h for hours, and d for days |
| Interruptions | Can be interrupted using signals, e.g., pressing Ctrl+C to send a SIGINT signal |
| Output | None |
Explore related products
What You'll Learn

Syntax and usage
The sleep command is a versatile tool that introduces delays in script execution. It is available in Unix, Unix-like, Linux, and other operating systems. The syntax is simply "sleep N", where N is a number (whole or decimal) that represents the duration of the delay in seconds. The system reads the number after "sleep" as seconds by default, but you can also specify time intervals in minutes, hours, or days using suffixes. For example, "sleep 6" for a 6-second delay, or "sleep 3m" for a 3-minute delay.
The sleep command is particularly useful when the execution of a command depends on the successful completion of a previous one. It can be used to pause processes and let them run again afterward, with the duration and resumption of the operation left to the user's discretion. It is often used in shell scripts, where it can be customized and integrated with other commands.
In Linux, the sleep command can be used in combination with other commands, such as "kill -0", to monitor the status of a background process and introduce delays between checks. It can also be used to manage latency and provide the CPU with enough time to perform calculations before the next iteration.
The sleep command has no output and serves as a pause button, enabling computers to wait for a specified duration before proceeding to the next task in a script. It provides precise control over time delays and enhances overall efficiency in Linux operations.
It's important to note that the sleep command only accepts one command-line argument, which states the sleep interval. Additionally, consecutive executions of the sleep command are possible, and you can specify the time unit using "s" for seconds, "m" for minutes, "h" for hours, and "d" for days.
Bugs' Sleep Patterns: Daytime Dozing or Nighttime Napping?
You may want to see also
Explore related products

Creating a dummy job
The sleep command is a versatile tool for introducing delays in script execution. It is available in Unix, Unix-like, and other operating systems, including Linux and Windows. The basic syntax is "sleep Number [Suffix]," where the number indicates the duration and the suffix (s, m, h, or d) specifies the unit of time. For example, "sleep 6" or "sleep 3m" pauses execution for 6 seconds or 3 minutes, respectively. The default unit is seconds, so "sleep 6" and "sleep 6s" are equivalent.
To create a dummy job, you can use the sleep command to introduce a delay between commands or processes. This can be useful when the execution of a command depends on the successful completion of a previous one. For instance, if you want to play an mp3 file after a delay, you can use "sleep 7h30m; mplayer alarm.mp3". Here, the system will wait for 7 hours and 30 minutes before executing the "mplayer alarm.mp3" command.
The sleep command can also be used to schedule tasks and enforce a time between the execution of two commands. For example, "sleep 1; echo 'Hello, world!'" will execute "echo 'Hello, world!'" after a one-second delay. This allows for precise control over the timing of automated tasks and enhances overall efficiency in Linux operations.
Additionally, the sleep command can be interrupted using signals. For example, pressing "Ctrl+C" sends a SIGINT signal, terminating the sleep. This provides flexibility in managing and interrupting the sleep duration as needed.
Sleep Comfortably at Work: Tricks for Power Naps
You may want to see also
Explore related products

Interrupting sleep with signals
Interrupted sleep can have several negative effects on a person's health and well-being. It involves frequent awakenings during the night, disrupting the sleep cycle and causing daytime sleepiness, cognitive decline, mood disturbances, and health risks. This can happen due to various factors such as age, stress, and lifestyle.
In the context of computing, interruptions during the sleep command can occur due to signals. The sleep command in Unix, Unix-like, and other operating systems suspends program execution for a specified time. However, signals can cause the sleep function to be interrupted and return early. This can be an issue for programs that require uninterrupted sleep to function correctly.
To address this, there are a few methods that can be employed. One approach is to use a custom signal handler to manage the signals and prevent them from interrupting the sleep function. Another method is to block and unblock signals using functions like sigprocmask() or signal(). Additionally, the POSIX library offers a solution by keeping signals blocked and using pselect to unblock them atomically during the wait.
It is worth noting that different signals and operating systems may exhibit varying behaviors when it comes to interrupting the sleep command. For example, using a regular signal (SIGUSR1) may not always work as intended and could result in the process being killed. Therefore, it is important to test and choose the appropriate method to handle interruptions effectively.
Sleep Deprived EEGs: Brain Waves and Sleep Patterns
You may want to see also
Explore related products

Specifying time units
The sleep command is a versatile tool for introducing delays in script execution. Its syntax is defined as sleep NUMBER[SUFFIX], where NUMBER is an integer indicating the time period in seconds. The default unit is seconds, but you can also specify the time unit using suffixes like "s" for seconds, "m" for minutes, "h" for hours, and "d" for days. These suffixes make the command more human-readable and provide flexibility in defining durations.
For example, to pause the execution of a script for 3 minutes, you would use the command "sleep 3m". Similarly, "sleep 3h" would pause the execution for 3 hours. You can also use decimal values to specify fractional seconds, such as "sleep 3.5s" for 3.5 seconds.
The sleep command can be used in Linux and Unix-like systems to suspend the calling process for a specified time. It is particularly useful when you need to introduce delays between commands or processes. For instance, you can use it to schedule the system to play an mp3 file after a specified time or to make echo commands execute in one-second intervals.
The GNU Project's implementation of sleep allows users to pass an arbitrary floating point or multiple arguments. For example, "sleep 5h 30m" will work on any system that uses GNU sleep, including Linux. However, note that "sleep 5h30m" is illegal since sleep takes only one value and unit as an argument.
Sleep Deprivation: The Dangerous Effects of 48-Hour Wakefulness
You may want to see also
Explore related products
$4.88 $5.47

How it works with other commands
The sleep command is designed to work in combination with other Linux commands. For instance, it can be used to schedule the system to play an mp3 file after a specified time. In this case, the command uses mplayer to play an alarm after a seven-hour and thirty-minute delay.
The sleep command can also be used to enforce a time between the execution of two commands. For example, the following command makes echo commands execute in one-second intervals:
Sleep 1
Echo "First command"
Sleep 1
Echo "Second command"
The sleep command can be interrupted using signals, such as pressing Ctrl+C, which sends a SIGINT signal, terminating the sleep. This allows users to gracefully interrupt the sleep duration and proceed with other actions.
The sleep command is also useful for creating dummy jobs, which help delay 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 defined by a number. For example, "sleep 5" pauses the execution for 5 seconds.
The sleep command can be used in the live shell window as well as in the shell or bash jobs, or it can be used in a combination of both.
Moonlight Blues: Sleep Disruption Before Moonrise
You may want to see also
Frequently asked questions
The sleep command is a system call that pauses a process for a specified period of time. It is available on Linux, Unix, Unix-like systems, IBM i, and Microsoft Windows.
The sleep command works by requesting that the operating system remove the program from the list of programs that are eligible to run and put it back on the list after the specified time has passed. The syntax for the sleep command is: $ sleep NUMBER[SUFFIX], where the suffix can be used to specify the unit of time (s for seconds, m for minutes, h for hours, etc.).
Some examples of using the sleep command include:
- sleep 5: Pause for 5 seconds
- sleep 2m: Pause for 2 minutes
- sleep 3h: Pause for 3 hours
- sleep 8h && mplayer wake-up.mp3: Pause for 8 hours, then play the music file "wake-up.mp3"











































