What does the sleep command do in Linux?

Can you explain to me the sleep command in Linux? I read somewhere that it can pause a bash shell script. How can I use the Linux sleep command to pause a bash script?

You can use sleep command to pause execution of shell scripts or commands for a given period on a Linux or Unix-like systems. This page explains syntax and usage of the sleep command in Linux operating systems.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements sleep command on Linux or Unix
Est. reading time 3 minutes

So, what does the sleep command do in Linux?

  1. /bin/sleep is Linux or Unix command to delay for a specified amount of time.
  2. You can suspend the calling shell script for a specified time. For example, pause for 10 seconds or stop execution for 2 mintues.
  3. In other words, the sleep command pauses the execution on the next shell command for a given time.
  4. GNU version of sleep command supports additional options
  5. For example, suspend a bash shell script or command prompt for five seconds, type: sleep 5
  6. Common examples of sleep commands include scheduling tasks and delaying the execution to allow a process to start. Another usage is waiting until a wifi network connection available to stream large file over the network.

Sleep command syntax

The syntax for the sleep command is as follows:
In addition to seconds, [SUFFIX] can be as follows on GNU/Linux:

  1. s for seconds (the default).
  2. m for minutes.
  3. h for hours.
  4. d for days.

Above options are only supported on GNU version of Linux and not on macOS/Unix/*BSD family of oses. Therefore, for non-GNU/Linux system try:
sleep 5
sleep 2

Sleep command examples

To sleep for 13 seconds, use:
sleep 13
For instance, sleep for 0.5 or 2.5 seconds too, try:
sleep 0.5
sleep 2.5
So a floating point number allowed. However, sleep 2h30m not allowed. Want to sleep for 2 minutes? Try:
sleep 2m
Halt or sleep for 2 hours, use:
sleep 2h
First sleep for 8 hours and after that play music file named wake-up.mp3
sleep 8h && mplayer wake-up.mp3

How to use the Linux sleep command to pause a bash script

Let us see a simple example that pause script for 10 seconds.

# Name: sleep-demo.sh
# Purpose: bash script examples that demos sleep command
# Author: Vivek Gite {https://www.cyberciti.biz}
# -----------------------------------------------------------
echo "Current time: $(date +%T)"
echo "Hi, I'm sleeping for ${SLEEP_TIME} seconds ..."
sleep ${SLEEP_TIME}
echo "All done and current time: $(date +%T)"

Run it as follows (see how to run shell script in Linux for more information):
chmod +x sleep-demo.sh

Sleep command in action

sleep command shell script examples

The shell script will start by showing current time on screen. After that, our shell script tells you how to quit and will continue to display current time on screen:

## run while loop to display date and hostname on screen ##
while [ : ]
    tput cup 5 5
    echo "$(date) [ press CTRL+C to stop ]"
    tput cup 6 5
    sleep 1

How to pause my bash shell script for 10 second before continuing

Try the read command as follows:

read -p "text" -t seconds
read -p "Waiting 10 seconds for CDN/Cloud to clear cache from proxy server" -t 10
echo "Uploading a fresh version of gif file now ...."
./upload.py "$gif_file" server1.cyberciti.biz

Let’s take a look at a more advanced example of sleep

         mkfifo $FIFO || exit 1
         flush_and_wait | "$MYSQL" $MYSQL_OPTS &
         # wait until every block is flushed #
         # add sleep 1 second to slow down a bit #
         while [ "$(echo 'SHOW STATUS LIKE "Key_blocks_not_flushed"' |\
                  "$MYSQL" $MYSQL_OPTS | tail -1 | cut -f 2)" -gt 0 ]; do
             sleep 1

Another example that shows advanced usage of sleep command:

                        # workaround for a possible latency caused by udev, sleep max. 10s
                        if kernel_is_2_6_or_above ; then
                                for x in `seq 100` ; do
                                        (exec 6<> /dev/net/tun) > /dev/null 2>&1 && break;
                                        sleep 0.1


You learned how to use the Linux sleep command. It is one of the most straightforward commands, and it only accepts one command line argument which states the sleep interval. It is similarly to the clear command that only accepts one argument on Linux. For more information see GNU docs here.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Haidee Diadumenianus Jun 13, 2021 @ 2:15

    I was looking for how sleep command works and examples and this page helped me.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum