🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

sleep Command

Beginner Shell Scripting man(1)

Delay for a specified amount of time

👁 9 views 📅 Updated: Mar 15, 2026
SYNTAX
sleep NUMBER[SUFFIX]

What Does sleep Do?

sleep pauses execution for a specified duration. It is one of the simplest yet most useful commands, essential for adding delays in scripts, rate limiting, polling loops, and countdown timers.

sleep accepts durations in seconds (default), minutes (m), hours (h), or days (d). It supports fractional seconds for sub-second delays.

sleep is commonly used in retry loops, monitoring scripts, cron job scheduling helpers, and anywhere you need to wait before the next action.

Options & Flags

OptionDescriptionExample
N Sleep for N seconds sleep 5
Nm Sleep for N minutes sleep 5m
Nh Sleep for N hours sleep 2h
Nd Sleep for N days sleep 1d
0.N Sleep for fractional seconds sleep 0.5
multiple Add multiple durations sleep 1m 30s

Practical Examples

#1 Pause for 5 seconds

Pauses execution for 5 seconds.
$ sleep 5

#2 Retry loop

Polls a health endpoint every 2 seconds until it responds.
$ until curl -s http://localhost:8080/health; do echo "Waiting..."; sleep 2; done

#3 Rate limiting

Adds a half-second delay between requests to avoid rate limiting.
$ for url in $(cat urls.txt); do curl -s "$url" > /dev/null; sleep 0.5; done

#4 Countdown timer

Counts down from 10 to 1 with one-second intervals.
$ for i in $(seq 10 -1 1); do echo "$i..."; sleep 1; done; echo "Go!"

#5 Delayed command

Sends a notification after 5 minutes.
$ sleep 5m && notify-send "Break time!"

#6 Background delay

Schedules nginx restart in 1 hour as a background job.
$ (sleep 3600 && systemctl restart nginx) &

Tips & Best Practices

Fractional seconds: sleep 0.1 pauses for 100ms. Useful for polling loops and rate limiting without being too slow.
Multiple durations: sleep 1m 30s sleeps for 1 minute and 30 seconds. Durations are added together.
Not precise for timing: sleep is not a precision timer. System load can cause slight delays. For precise timing, use dedicated scheduling tools.

Frequently Asked Questions

How do I sleep for milliseconds?
Use fractional seconds: sleep 0.5 for 500ms, sleep 0.001 for 1ms. Not all implementations support sub-second precision.
How do I add a delay in a bash script?
Simply use sleep N where N is seconds. For minutes: sleep 5m. For hours: sleep 2h.
Can I cancel a sleep?
Press Ctrl+C to interrupt sleep. In scripts, you can kill the sleep process by PID.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →