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
🌐
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 - The sleep command is a useful way to add pauses in your Bash script. Used in conjunction with other commands, sleep can help you create a timed alarm, run operations in the correct order, space out attempts to connect to a website, and more.
Discussions

linux - Bash script how to sleep in new process then execute a command - Stack Overflow
So, I was wondering if there was a bash command that lets me fork a process which sleeps for several seconds, then executes a command. Here's an example: sleep 30 'echo executing...' & ^This ... More on stackoverflow.com
🌐 stackoverflow.com
Loop until success
You could try an until loop. until curl "$arg"; do sleep 10 done It's essentially the same as while ! curl "$arg"; do But nobody ever remembers or cares about the until loop :( More on reddit.com
🌐 r/bash
4
0
March 15, 2024
Why is my command in Interruptible Sleep and how do I wake it?
if it is sleeping, it is something iqtree is doing itself. Nothing to do with bash. It is either locking/awaiting on a resource and sleeping until it becomes available or it is explicitly sleeping. It is likely waiting for an event to occur, at which point it will interrupt itself. More on reddit.com
🌐 r/bash
2
1
February 29, 2024
I am trying to pause or return an output for my bash script, but it keeps on exiting
Neither “pause” nor “return” are native bash commands, as far as I know. If you want to pause a script, you can use the ‘sleep’ function, i.e. sleep 20s will pause the script for 20 seconds. If you want to wait for user interaction, you can do something like read -p “Press ENTER to continue” Which pause the script until the user presses the ENTER key. These are just some examples, some more context about what you’re trying to do may make it easier to provide a specific solution More on reddit.com
🌐 r/linuxquestions
9
2
September 23, 2023
People also ask

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
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
🌐
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 in Bash is used to delay the execution of a script or a command for a given period. This duration can be specified in seconds (default), minutes, hours, or days, making it versatile for different timing needs.
🌐
Linuxize
linuxize.com › home › linux commands › linux sleep command (pause a bash script)
Linux Sleep Command (Pause a Bash Script) | Linuxize
January 31, 2026 - Then the sleep command pauses the script for 5 seconds. Once the specified time period elapses, the last line prints the current time. ... The following script checks whether a host is online every 5 seconds and notifies you when it becomes ...
🌐
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 - It is possible to assign a variable to specify the sleep command duration. To do that, create an example shell script. Take the following steps: 1. Use a text editor like Vim to create a new script file. 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") echo "Time after sleep: ${CURRENT_TIME}"
🌐
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.
Find elsewhere
🌐
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 [ : ] do clear tput cup 5 5 date tput cup 6 5 echo "Hostname : $(hostname)" sleep 1 done
🌐
Hostinger
hostinger.com › home › tutorials › linux sleep command: syntax, options, and examples
How to use the Linux sleep command
December 22, 2025 - The Linux sleep command pauses script or command executions for a specific time. It is helpful to prevent your system from running a process too soon or too frequently while still keeping it automated.
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.

🌐
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 - Run it as follows (see how to run shell script in Linux for more information): $ chmod +x sleep-demo.sh $ ./sleep-demo.sh ... The shell script will start by showing current time on screen.
🌐
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 - The sleep command is commonly used in scripts where you need to introduce a delay between two commands. Here are a few use cases: Pausing between Commands: Suppose you want to create a script that displays a message, waits for a few seconds, ...
🌐
Joshuarosato
joshuarosato.com › posts › bash-sleep-command
Mastering the Bash Sleep Command: A Complete Guide with Examples | Joshua Rosato
December 9, 2025 - The sleep command helps space out requests evenly over time. 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/
🌐
Linux Handbook
linuxhandbook.com › bash-sleep
Using Linux Sleep Command in Bash Scripts
July 1, 2021 - Though you can use it in a shell directly, the sleep command is commonly used to introduce a delay in the execution of a bash script.
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.
🌐
Baeldung
baeldung.com › home › processes › infinite sleep for infinite blocking in bash
Infinite Sleep for Infinite Blocking in Bash | Baeldung on Linux
May 16, 2024 - Thus, we can use the while loop to initiate an infinite sleep in Bash and block a process entirely: ... This loop will execute the sleep 1 command repeatedly, indefinitely putting the shell to sleep for one second at a time.
🌐
CodeFatherTech
codefather.tech › home › blog › bash sleep command: a quick guide to use it in your scripts
Bash Sleep Command: A Quick Guide to Use It in Your Scripts
June 27, 2025 - Sleeping for 6 seconds..." sleep 6 else echo "File stage1.complete exists. Stage 1 complete, starting Stage 2..." rm stage1.complete exit fi done · In the second Bash shell script, we have an infinite loop. At every iteration of the script: Check if the file stage1.complete is present. ... If the file exists remove the stage1.complete file and stop the execution using the Bash exit command.
🌐
DiskInternals
diskinternals.com › home › linux reader › how to use shell script sleep command
How to Use Shell Script Sleep Command | DiskInternals
July 29, 2021 - Simply, the Sleep command is used in Bash shell scripts to delay the runtime of a script for a specified period before it starts running again.
🌐
Earthly
earthly.dev › blog › using-sleep
Shell Scripting with sleep: Using Delays Strategically - Earthly Blog
July 19, 2023 - Learn how to strategically use the `sleep` command in shell scripting to introduce delays and control the timing of actions in your Linux scripts. ...
🌐
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 ... The Bash `Sleep` Command serves as a pause button, enabling computers to wait for a specified duration before proceeding to the next task in a script....