Linux Command Reference ยท Processes and Signals
Linux sleep command
Reference for the Linux sleep command: pause for seconds, fractions, minutes, hours or days, combine suffixes, use it in retry loops and see why a sleep is often not the right fix.
sleep does nothing for a given amount of time and then exits. It is used in scripts to space out retries, to give a background process a moment to start, or to slow down a loop. While it sleeps it uses no CPU, so it is cheap to wait with.
The argument is a number followed by an optional unit. GNU sleep also accepts fractions and several arguments, which it adds together.
sleep NUMBER[SUFFIX]...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
sleep NUMBER[SUFFIX]... sleep infinity
| Suffix | Unit |
|---|---|
s (or none) |
Seconds |
m |
Minutes |
h |
Hours |
d |
Days |
NUMBER may be a decimal, such as 0.25 or 1.5m. With several arguments the total is the sum: sleep 1m 30s sleeps for 90 seconds. GNU coreutils also accepts infinity.
Returns: 0 after sleeping. On a bad argument (sleep abc) it prints sleep: invalid time interval 'abc' and returns 1. A signal such as SIGTERM ends it early.
Usage notes
- Fractions and suffixes are GNU extensions. POSIX
sleeptakes only whole seconds; on macOS and BSDsleep 1mis an error, though fractions work on recent versions. - Not exact.
sleepwaits at least the time given; scheduling adds a few milliseconds, and the clock can pause when the machine suspends. - Polling is a smell. A fixed pause is a guess. Prefer to wait for the real condition:
waitfor a background job, a loop that checks for a file, ortimeoutaround a check. Sleep inside such a loop only limits how often you check. - Signals.
sleepis a separate process, so atrapin the parent runs only aftersleepends. In a loop that must react quickly, runsleep 60 & wait $!. sleep infinityis handy to keep a container or a test process alive.- Not a rate limiter for parallel work: each process sleeps on its own.
- Builtin alternative: Bash can sleep without forking using
read -t 0.5 < /dev/zeroon an unused descriptor, but plainsleepis clearer.