Use the sleep command.

Example:

sleep .5 # Waits 0.5 second.
sleep 5  # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.

One can also employ decimals when specifying a time unit; e.g. sleep 1.5s

Answer from RydallCooper on Stack Overflow
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to use the linux sleep command with examples
Linux Sleep Command with Examples {Terminal and Bash}
January 27, 2025 - For example, type the following command: ... #!/bin/bash SLEEP_INTERVAL="30" CURRENT_TIME=$(date +"%T") echo "Time before sleep: ${CURRENT_TIME}" echo "Sleeping for ${SLEEP_INTERVAL} seconds" sleep ${SLEEP_INTERVAL} CURRENT_TIME=$(date +"%T") ...
People also ask

Does `sleep` use CPU while waiting?
No. The `sleep` command suspends the process and does not consume CPU cycles during the wait period.
🌐
linuxize.com
linuxize.com › home › linux commands › linux sleep command (pause a bash script)
Linux Sleep Command (Pause a Bash Script) | Linuxize
Can `sleep` accept decimal values?
Yes. The GNU version of `sleep` (used on Linux) supports floating-point numbers. For example, `sleep 0.5` pauses for half a second. The POSIX specification only requires integer support.
🌐
linuxize.com
linuxize.com › home › linux commands › linux sleep command (pause a bash script)
Linux Sleep Command (Pause a Bash Script) | Linuxize
How do I cancel a `sleep` in a script?
Press `Ctrl+C` to send `SIGINT` to the foreground process. For background sleep processes, use `kill PID` where PID is the process ID returned by `$!`.
🌐
linuxize.com
linuxize.com › home › linux commands › linux sleep command (pause a bash script)
Linux Sleep Command (Pause a Bash Script) | Linuxize
🌐
Linuxize
linuxize.com › home › linux commands › linux sleep command (pause a bash script)
Linux Sleep Command (Pause a Bash Script) | Linuxize
January 31, 2026 - To terminate a background sleep process, use kill: ... Can sleep accept decimal values? Yes. The GNU version of sleep (used on Linux) supports floating-point numbers. For example, sleep 0.5 pauses for half a second.
🌐
freeCodeCamp
freecodecamp.org › news › bash-sleep-how-to-make-a-shell-script-wait-n-seconds-example-command
Bash Sleep – How to Make a Shell Script Wait N Seconds (Example Command)
September 13, 2021 - For example, sleep 2m 30s will create a pause of 2 and a half minutes. Note that to achieve the same result on a MacOS or BSD machine, you would run the equivalent command sleep 150, as 2 minutes and 30 seconds is equal to 150 seconds.
🌐
Namehero
namehero.com › blog › how-to-use-bash-sleep-and-why
How to Use Bash Sleep and Why
November 6, 2024 - Here's what the "sleep" command does in the bash environment, and how to use it to delay execution or implement code to retry scripts.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › linux / unix bash script sleep or delay a specified amount of time
Linux / UNIX Bash Script Sleep or Delay a Specified Amount of Time - nixCraft
May 26, 2023 - ## run commmand1, sleep for 1 minute and finally run command2 ## command1 && sleep 1m && command2 ## sleep in bash for loop ## for i in {1..10} do do_something_here sleep 5s done ## run while loop to display date and hostname on screen ## while ...
🌐
Heatware
heatware.net › linux › sleep-in-shell-script-using-bash
5 Ways How to 'Sleep' in a Linux Bash Shell Script - HeatWare
February 11, 2025 - Use Ctrl+C in the terminal to interrupt a running sleep command. Yes! For example, sleep 0.5s pauses for half a second.
Find elsewhere
🌐
Linux Handbook
linuxhandbook.com › bash-sleep
Using Linux Sleep Command in Bash Scripts
July 1, 2021 - If you run it with the time command, you’ll see that the bash script actually ran for (a slightly) more than 5 seconds. time ./sleep.sh Sleeping for 5 seconds
🌐
InterServer
interserver.net › home › linux and commands › how to use the sleep command in bash
How to Use the sleep Command in Bash - Interserver Tips
August 4, 2025 - The sleep command is often used in shell scripts to manage timing and control the flow of execution. Here’s an example of a simple script that uses sleep: #!/bin/bash echo "Starting the script..." sleep 3 echo "This message appears after a 3-second pause."
🌐
AlexHost
alexhost.com › home › faq › using the sleep command in bash scripts on linux
Using the Sleep Command in Bash Scripts on Linux
June 19, 2025 - For example, if you want to download a file and retry every 10 seconds until the download is successful, you can use a loop with sleep: #!/bin/bash while true do wget http://example.com/file.zip && break echo "Download failed.
🌐
Joshuarosato
joshuarosato.com › posts › bash-sleep-command
Mastering the Bash Sleep Command: A Complete Guide with Examples | Joshua Rosato
December 9, 2025 - while ! ping -c 1 example.com &> /dev/null; do echo "Waiting for network..." sleep 5 done · This pattern is commonly used in system administration scripts where you need to wait for network services, databases, or other dependencies to become available before proceeding. #!/bin/bash # Backup script with delay between operations tar -czf backup.tar.gz /important/data sleep 10 # Give system time to recover rsync backup.tar.gz remote-server:/backups/
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › what does the sleep command do in linux?
What does the sleep command do in Linux? - nixCraft
December 13, 2022 - #!/bin/bash # Name: sleep-demo.sh ...------------------------------------------- SLEEP_TIME="10" echo "Current time: $(date +%T)" echo "Hi, I'm sleeping for ${SLEEP_TIME} seconds ..." sleep ${SLEEP_TIME} echo "All done and current ...
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › sleep-command-in-linux-with-examples
sleep Command in Linux with Examples - GeeksforGeeks
July 19, 2024 - This article covered basic usage with examples like `sleep 6`, demonstrated the use of suffixes as in `sleep 3m`, and explored advanced options such as interrupting sleep with signals.
🌐
Linux Hint
linuxhint.com › sleep_command_linux
Sleep Command in Linux – Linux Hint
In the following script, sleep command is used with numeric value 2 only and no suffix is used. So, if you run the script then the string “Task completed” will print after waiting for 2 seconds. #!/bin/bash echo "Waiting for 2 seconds..." sleep 2 echo "Task Completed"
🌐
Delft Stack
delftstack.com › home › howto › linux › how to use the sleep command in bash
How to Use the sleep Command in Bash | Delft Stack
March 14, 2025 - The sleep command can also be used in loops. For example, if you want to create a simple countdown timer, you could do something like this: #!/bin/bash for i in {5..1}; do echo "$i..." sleep 1 done echo "Time's up!"
Top answer
1 of 8
87

Bash has a "loadable" sleep which supports fractional seconds, and eliminates overheads of an external command:

$ cd bash-3.2.48/examples/loadables
$ make sleep && mv sleep sleep.so
$ enable -f sleep.so sleep

Then:

$ which sleep
/usr/bin/sleep
$ builtin sleep
sleep: usage: sleep seconds[.fraction]
$ time (for f in `seq 1 10`; do builtin sleep 0.1; done)
real    0m1.000s
user    0m0.004s
sys     0m0.004s

The downside is that the loadables may not be provided with your bash binary, so you would need to compile them yourself as shown (though on Solaris it would not necessarily be as simple as above).

As of bash-4.4 (September 2016) all the loadables are now built and installed by default on platforms that support it, though they are built as separate shared-object files, and without a .so suffix. Unless your distro/OS has done something creative (sadly RHEL/CentOS 8 build bash-4.4 with loadable extensions deliberately removed), you should be able to do instead:

[ -z "$BASH_LOADABLES_PATH" ] &&
  BASH_LOADABLES_PATH=$(pkg-config bash --variable=loadablesdir 2>/dev/null)  
enable -f sleep sleep

(The man page implies BASH_LOADABLES_PATH is set automatically, I find this is not the case in the official distribution as of 4.4.12. If and when it is set correctly you need only enable -f filename commandname as required.)

If that's not suitable, the next easiest thing to do is build or obtain sleep from GNU coreutils, this supports the required feature. The POSIX sleep command is minimal, older Solaris versions implemented only that. Solaris 11 sleep does support fractional seconds.

As a last resort you could use perl (or any other scripting that you have to hand) with the caveat that initialising the interpreter may be comparable to the intended sleep time:

$ perl -e "select(undef,undef,undef,0.1);"
$ echo "after 100" | tclsh
2 of 8
183

The documentation for the sleep command from coreutils says:

Historical implementations of sleep have required that number be an integer, and only accepted a single argument without a suffix. However, GNU sleep accepts arbitrary floating point numbers. See Floating point.

Hence you can use sleep 0.1, sleep 1.0e-1 and similar arguments.

Top answer
1 of 5
53

When a Bash script is running a sleep, here's what the pstree might look like:

bash(10102)───sleep(8506)

Both have process IDs (PIDs), even when running as a script. If we wanted to interrupt the sleep, we'd send kill 8506 and the Bash session would resume... The problem is in a scripted environment we don't know the PID of the sleep command and there isn't a human to look at the process tree.

We can get the PID of the Bash session through the $$ magic variable. If we can store that somewhere, we can then target instances of sleep that are running underneath that PID. Here's what I'd put in the script:

# write the current session's PID to file
echo $$ >> myscript.pid

# go to sleep for a long time
sleep 1000

And then we can tell pkill to nuke sleep instances running underneath that PID:

pkill -P $(<myscript.pid) sleep

Again, this is limiting itself to only sleep processes running directly under that one Bash session. As long as the PID was logged correctly, this makes it a lot safer than killall sleep or pkill sleep, which could nuke any sleep process on the system (permissions allowing).

We can prove that theory with the following example where we have three separate bash sessions, two running sleep. Only because we're specifying the PID of the top-left bash session, only its sleep is killed.


An alternative approach is to push sleep into the background, store its PID and then return it to the foreground. In the script:

sleep 1000 &
echo $! > myscript.sleep.pid
fg

And to kill it:

kill $(<myscript.sleep.pid)
2 of 5
5

You could write your script to handle ("trap") other signals from kill etc. so you could modify the scripts behaviour as needed. See man bash:

SIGNALS
   When  bash  is  interactive,  in the absence of any traps, it ignores SIGTERM (so that kill 0 does not
   kill an interactive shell), and SIGINT is caught and handled (so that the wait builtin  is  interrupt-
   ible).   In all cases, bash ignores SIGQUIT.  If job control is in effect, bash ignores SIGTTIN, SIGT-
   TOU, and SIGTSTP.

   Non-builtin commands run by bash have signal handlers set to the values inherited by  the  shell  from
   its  parent.   When  job  control is not in effect, asynchronous commands ignore SIGINT and SIGQUIT in
   addition to these inherited handlers.  Commands run as a result of  command  substitution  ignore  the
   keyboard-generated job control signals SIGTTIN, SIGTTOU, and SIGTSTP.

   The shell exits by default upon receipt of a SIGHUP.  Before exiting, an interactive shell resends the
   SIGHUP to all jobs, running or stopped.  Stopped jobs are sent SIGCONT to ensure that they receive the
   SIGHUP.   To  prevent the shell from sending the signal to a particular job, it should be removed from
   the jobs table with the disown builtin (see SHELL BUILTIN COMMANDS below) or  marked  to  not  receive
   SIGHUP using disown -h.

   If  the huponexit shell option has been set with shopt, bash sends a SIGHUP to all jobs when an inter-
   active login shell exits.

   If bash is waiting for a command to complete and receives a signal for which a trap has been set,  the
   trap  will not be executed until the command completes.  When bash is waiting for an asynchronous com-
   mand via the wait builtin, the reception of a signal for which a trap has been set will cause the wait
   builtin  to  return immediately with an exit status greater than 128, immediately after which the trap
   is executed.
🌐
Hostinger
hostinger.com › home › tutorials › linux sleep command: syntax, options, and examples
How to use the Linux sleep command
December 22, 2025 - #!/bin/bash while true; do if systemctl is-active --quiet apache2; then echo "Apache is running." else echo "Apache is not running." fi sleep 15 # Wait 15 seconds before checking again done
🌐
Linux Hint
linuxhint.com › bash-sleep-command
Bash Sleep Command – Linux Hint
Create a Bash file with the following script that prints the number from 1 to 5 with 2 seconds intervals using the “sleep” command. An infinite for loop is used to print the $counter value after 2 seconds until the $counter value is equal to 5. The “sleep” command is used with the value ...