Quick take: The sleep command pauses for a given time: sleep 5 waits five seconds. Add a suffix for other units — sleep 2m for minutes, sleep 1h for hours — and use it to space out actions in scripts.

Introduction

The sleep command does exactly one thing: it waits for a specified time before returning. That simplicity makes it essential in scripts — pacing a loop, waiting for a service to start, spacing out retries, or building simple delays into automation.

Syntax

The basic syntax of the sleep command is:

sleep NUMBER[SUFFIX]

Common Options and Parameters

The most useful options and parameters for the sleep command:

OptionDescription
NSleep N seconds (the default unit).
NsSeconds.
NmMinutes.
NhHours.
NdDays.
N1 N2 ...Sum multiple durations (e.g. sleep 1m 30s).

Practical Examples

Real sleep commands you can run today:

# Pause for 5 seconds
sleep 5
# Pause for 2 minutes
sleep 2m
# Combine durations (1 min 30 sec)
sleep 1m 30s
# Wait then run a command
sleep 10 && systemctl restart nginx
# Pace a loop in a script
for i in 1 2 3; do echo $i; sleep 1; done
# Retry until a service responds
until curl -s localhost:8080; do sleep 2; done

Tips and Best Practices

  • Default unit is seconds; add m, h, or d for longer waits — sleep 0.5 also works for sub-second pauses.
  • Use sleep in retry loops to wait between attempts, e.g. polling until a service comes up.
  • For pausing until a specific time of day, combine with at or compute the delay; sleep handles relative durations only.

Final Thoughts

sleep is the simplest possible command — it waits — but it is indispensable in scripting, where pacing, polling, and timed delays are everywhere. Remember the unit suffixes (s, m, h) and that you can sum durations. For scheduling at an absolute time rather than a relative delay, reach for at or cron.

FAQ: sleep Command in Linux

How do I pause for a number of seconds in Linux?+

Run sleep N, for example sleep 5 to wait five seconds. Seconds are the default unit, so no suffix is needed.

How do I sleep for minutes or hours?+

Add a unit suffix: sleep 2m for two minutes, sleep 1h for an hour, or sleep 1d for a day. You can also combine them, like sleep 1m 30s.

How do I use sleep in a script?+

Place sleep between actions to pace them, for example in a loop: for i in ...; do task; sleep 1; done. It is also used in retry loops to wait between attempts.

Can sleep handle fractions of a second?+

Yes, the GNU sleep accepts decimals, so sleep 0.5 waits half a second. This is useful for short pauses in scripts.

How do I wait until a service is ready?+

Use a loop with sleep: until curl -s localhost:8080 >/dev/null; do sleep 2; done polls every two seconds until the service responds.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support