LinuxCommandLibrary

sleep

Pause script execution for a specified duration

TLDR

Delay in seconds

$ sleep [seconds]
copy

Execute a specific command after 20 seconds delay
$ sleep 20 && [command]
copy

SYNOPSIS

sleep NUMBER[SUFFIX]...
sleep OPTION...

PARAMETERS

NUMBER
    The duration to sleep for. Can be a non-negative integer or a floating-point number (e.g., '1.5').

SUFFIX
    Optional unit suffix: s for seconds (default), m for minutes, h for hours, d for days.

--help
    Display a help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The sleep command is used to delay or pause the execution of a shell script or a command for a specified amount of time. It is a fundamental utility commonly employed in shell scripting for various tasks requiring a delay, such as waiting for a process to complete, staggering the execution of commands, or implementing simple rate limiting.

The duration can be specified as a number, and on most modern Linux systems (specifically GNU Coreutils), it also supports a unit suffix (seconds, minutes, hours, or days) and floating-point numbers for sub-second delays. If no unit suffix is provided, the duration is interpreted in seconds by default.

CAVEATS

The actual sleep duration might be slightly longer than requested due to system load and scheduling overhead.
The command can be interrupted by signals like Ctrl+C (SIGINT), which will terminate the sleep prematurely.

FLOATING-POINT SUPPORT

GNU sleep supports floating-point numbers for the duration, allowing for sub-second delays (e.g., sleep 0.5 for half a second).

MULTIPLE ARGUMENTS

On GNU systems, multiple NUMBER[SUFFIX] arguments can be provided, and their durations will be summed (e.g., sleep 1m 30s sleeps for 90 seconds).

DEFAULT UNIT

If no suffix is provided for the NUMBER, the duration is interpreted as seconds by default.

HISTORY

The sleep command is a fundamental utility in Unix-like operating systems, dating back to the early days of Unix. It is part of the GNU Core Utilities, providing basic system commands. Over time, its functionality has been standardized and enhanced, particularly with the addition of floating-point number support for sub-second delays and the ability to sum multiple time arguments, making it more versatile for modern scripting needs.

SEE ALSO

nanosleep(2), at(1), watch(1)

Copied to clipboard