sleep
Overview
sleep suspends execution for a specified time. Used in shell scripts for pacing, simple retries, and demos. For precise timers, event-driven waits, or jittered backoff, higher-level tools may be better — but sleep remains the universal delay primitive.
Syntax
sleep NUMBER[SUFFIX]...GNU sleep accepts floating point and multiple arguments (sums them).
Time suffixes (GNU)
| Suffix | Unit |
|---|---|
s |
Seconds (default) |
m |
Minutes |
h |
Hours |
d |
Days |
Examples with Explanations
Basics
sleep 5
sleep 0.5
sleep 2m
sleep 1h
sleep 1m 30s # GNU: 90 seconds totalSimple retry loop
until ping -c1 -W1 gateway >/dev/null; do
sleep 2
doneExponential backoff (bash)
delay=1
for i in 1 2 3 4 5; do
curl -fsS https://example.com/ && break
sleep "$delay"
delay=$((delay * 2))
doneRate limiting
while read -r host; do
ssh "$host" 'uname -r'
sleep 0.2
done < hosts.txtBackground heartbeat
while true; do
date -Is >> /tmp/heartbeat
sleep 60
done &Prefer systemd timers for production heartbeats.
Interruptible
sleep 300
# Ctrl-C sends SIGINT to foreground sleepPortable note
# POSIX: integer seconds only on some platforms
sleep 5
# fractional may require GNU coreutilsNotes / Pitfalls
- Busy loops without sleep burn CPU — always throttle polls.
sleep infinityworks on GNU; not portable — use large numbers ortail -f /dev/null.- Sleep drift: not a real-time scheduler; long loops accumulate error.
- Don’t use sleep as the only readiness check for services — probe health endpoints.
- In pipelines, know which process sleeps.
2026-relevant notes
- Prefer
systemd-runtimers / cron /watchfor periodic work. - Kubernetes readiness/liveness already handle waits — avoid crude sleep in hot paths.
timeoutpairs with commands that must not hang forever.
Additional Resources
man sleep