Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Use the Linux sleep Command

Pause a command or script for a number of seconds, minutes, hours or days.

How-To Guides1 min read3 screenshots

What sleep does

sleep waits for a set time and then ends. It is mostly used in scripts to add delays.

Syntax

sleep NUMBER[SUFFIX]
  • NUMBER is the length of the pause.
  • SUFFIX is the unit:

- s seconds (default) - m minutes - h hours - d days

Show the help:

sleep --help
The sleep help

Examples

Wait 5 seconds:

sleep 5
Sleeping for 5 seconds

Wait 2 minutes:

sleep 2m
Sleeping for 2 minutes

Wait 3 hours:

sleep 3h

Advanced use

Decimal numbers (GNU sleep):

sleep 2.5

Several values add up:

sleep 1 2 3

This waits 6 seconds.

In a loop:

for i in {1..5}; do
    echo "Iteration $i"
    sleep 2
done

In Bash scripts

Add a delay:

#!/bin/bash
echo "Starting task..."
sleep 10
echo "Task completed."

Repeat a job every hour:

#!/bin/bash
while true; do
    tar czf backup_$(date +%Y%m%d_%H%M).tar.gz /path/to/backup
    sleep 3600
done

For regular jobs, cron or a systemd timer is a better choice than a loop with sleep.

Run it in the background

sleep 60 && echo "Done" &

Quick recap

  • sleep 5 waits 5 seconds, sleep 2m waits 2 minutes.
  • Use it in scripts to add delays between steps.