<http://schema.org/articleBody>
"&amp;lt;h3&amp;gt;Introduction&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;This guide shows how to use the Linux sleep command to pause a bash script.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;On its own the sleep command is completely useless unless you like locking up your terminal window but as part of a script it can be used in many different ways including as a pause factor before retrying a command.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;For instance imagine you had a script that processed files copied from another server. The script should not start the copy process until all of the files have finished downloading. The download process is performed by a completely separate script.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The script for copying the files may well contain a loop to test whether all of the files have been downloaded (i.e. it knows there should be 50 files and when 50 files have been found the copy process is started).&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;There is no point the script continually testing as it takes up processor time. Instead you might choose to test whether there is enough files copied and if there aren&amp;amp;#39;t pause for a few minutes and then try again. The sleep command is perfect in these circumstances.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;How To Use The sleep Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;To use the Linux sleep command enter the following into the terminal window:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sleep 5s&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The above command will make your terminal pause for 5 seconds before returning you to the command line.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The sleep command requires the keyword sleep followed by the number you wish to pause by and then the unit of measure.\u00A0&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;You can specify the delay in seconds, minutes, hours or days.&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;s - seconds&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;m - minutes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;h - hours&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;d - days&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;When it comes to waiting days for something to happen it might be worth considering using a cron job to run the script at regular intervals as opposed to having a script running in the background for days on end.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The number for the sleep command doesn&amp;amp;#39;t have to be a whole number. You can also use floating point numbers.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;For example it is perfectly ok to use the following syntax:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;sleep 3.5s&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;h3&amp;gt;An Example Use For The Sleep Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;The following script shows how to use the sleep command to make a terminal based countdown clock:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;#!/bin/bash&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;x&amp;amp;#61;10&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;while [ $x -gt 0 ]&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;do&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;\u00A0 \u00A0 sleep 1s&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;\u00A0 \u00A0 clear&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;\u00A0 \u00A0 echo &amp;amp;#34;$x seconds until blast off&amp;amp;#34;&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;\u00A0 \u00A0 x&amp;amp;#61;$(( $x - 1 ))&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;done&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The script sets the variable x to 10. The while loop will continue to iterate whilst the value of x is greater than zero.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The sleep command pauses the script for 1 second each time around the loop.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The rest of the script clears the screen each iteration, displays the message &amp;amp;#34;x seconds until blast off&amp;amp;#34; (i.e. 10) and then subtracts 1 from the value of x.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Without the sleep command the script would zoom through and the messages would be displayed too quickly.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The sleep command only has a couple of switches.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The --help switch shows the help file for the sleep command. You can achieve the same thing by using the man command as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;man sleep&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The --version command shows the version of the sleep command that is installed on your system.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;The information returned by the --version switch is as follows:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;version number&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;copyright details&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;License&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Authors&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;h3&amp;gt;Further Reading&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;The following links highlight other Linux commands you might wish to know about:&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/output-text-to-the-screen-linux-echo-command-3572040&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;How to output text to the screen using the echo command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/operating-systems-unix-vs-windows-2180225&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;2&amp;quot;&amp;gt;How to find the directory portion of a file path using dirname&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/linux-grep-command-3571842&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;3&amp;quot;&amp;gt;Example uses of the grep command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/extract-tar-gz-files-2202057&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;4&amp;quot;&amp;gt;How to extract tar.gz files&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/download-file-from-command-line-2202055&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;5&amp;quot;&amp;gt;How to download files using the command line&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/move-files-with-linux-mv-command-2201103&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;6&amp;quot;&amp;gt;How to move files using the mv command&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;https://www.lifewire.com/what-does-cd-do-terminal-window-2183856&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;7&amp;quot;&amp;gt;What does cd ~ do when entered into the command line&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;"^^<http://www.w3.org/2001/XMLSchema#string>
<https://www.lifewire.com/use-linux-sleep-command-3572060>