Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

sleep

Wait for a given time.

Level
Everyday Linux
Group
Shell and help
Needs root
No
Package
coreutils

What it does

sleep NUMBER[SUFFIX] pauses: s = seconds (default), m = minutes, h = hours, d = days. Decimals and more numbers (added together) are allowed. It is used in scripts and as a harmless test process in labs.

How to write it

sleep NUMBER[SUFFIX]...

Options 3

Most used

NUMBER[smhd]
The time to wait; more values are added.
--help
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Wait 5 seconds

    sleep 5

    No output; the prompt comes back after 5 seconds.

  2. 2Minutes and hours

    sleep 2m; sleep 1.5h

    Suffixes s, m, h, d.

  3. 3Add values

    sleep 1m 30s

    Waits 90 seconds.

  4. 4A test process for labs

    sleep 3600 &

    Practice jobs, ps, kill and renice.

  5. 5Retry in a loop

    until curl -fs http://localhost/health; do sleep 2; done

    Wait until a service answers.

  6. 6Pace a loop

    for h in server1 server2; do ssh $h 'systemctl restart httpd'; sleep 30; done

    Rolling restart, one server at a time.

  7. 7Random delay for cron jobs

    sleep $((RANDOM % 300)); /usr/local/bin/report.sh

    Not all servers hit the API at the same second.

  8. 8Fractions of a second

    sleep 0.2

    Short pauses in scripts.

  9. 9Stop a long sleep

    kill %1

    sleep reacts to signals like other processes.

  10. 10Sleep forever (containers)

    sleep infinity

    Keeps a test container running.

Exit codes

0Done.
1Error or interrupted by a signal.