sleepx
Delay for a specified amount of time.
Mirrors GNU sleep. Run it as sleepx, or as gnux sleepx.
Synopsis
sleepx NUMBER[SUFFIX]...GNU reference
Description
sleepx pauses for NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours or 'd' for days. NUMBER need not be an integer: fractions (0.5), exponents (1e3) and hexadecimal floating-point values are accepted, as is 'infinity' (or 'inf') to pause until interrupted. Given two or more arguments, sleepx pauses for the sum of their values. Every operand is checked before the pause begins, so an invalid interval fails immediately.
Permissions
Needs no permissions; it touches nothing.
Use cases
- Pacing a retry or polling loop in a script.
- Giving a service time to start before the next step runs.
- Writing delays that behave the same in every shell, fractional seconds included.
- Rate-limiting a loop that calls an API or writes to a slow device.
- Waiting for a file or flag to appear before continuing.
- Keeping a container or background job alive with
sleepxinfinity. - Spacing out progress messages or demo output so it can be read.
- Simulating a slow command when testing timeouts, spinners or pipelines.
Flags
--help display this help and exit
--version output version information and exitExamples
Pause for half a second
sleepx 0.5Pause for one and a half minutes
sleepx 1m 30sPause for two hours
sleepx 2hUse a fraction of a larger unit (6 minutes)
sleepx 0.1hWrite the interval in scientific or hexadecimal notation
sleepx 1e-1 0x0.1p0Run the next command only after the pause
sleepx 2 && echox readyPrint a line every second, three times
for i in 1 2 3; do echox "tick $i"; sleepx 1; doneRetry a command every two seconds until it succeeds
until curl -fs localhost:8080/health; do sleepx 2; doneWait until a file appears
until [ -e ready.flag ]; do sleepx 0.5; done; echox foundRun a slow stand-in command in the background
sleepx 30 & echox "started $!"See an invalid interval rejected before any pause
sleepx 10x; echox "status: $?"Space out the steps of a gnux shell script
gnux shell -c 'echox start; sleepx 1; echox done'Block until interrupted
sleepx infinityExit status
| Status | Meaning |
|---|---|
| 0 | the full interval elapsed |
| 1 | an invalid interval or a command-line mistake |
Help in the terminal
sleepx --help # options, first examples, exit status
gnux help sleepx # this page: the full manual
gnux help sleepx --OPTION # one option in depth, with its examples