{"id":129226,"date":"2025-06-02T14:06:41","date_gmt":"2025-06-02T14:06:41","guid":{"rendered":"\/tutorials\/?p=129226"},"modified":"2025-12-22T12:46:42","modified_gmt":"2025-12-22T12:46:42","slug":"linux-sleep-command","status":"publish","type":"post","link":"\/tutorials\/linux-sleep-command","title":{"rendered":"Linux sleep command: Syntax, options, and examples"},"content":{"rendered":"<p>The Linux <strong>sleep<\/strong> 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.<\/p><p>If you use bash scripts to automate intricate tasks in your Linux system, the sleep command can be a handy tool to ensure processes run smoothly.<\/p><p>In this article, we&rsquo;ll explain what the sleep command in Linux does alongside its syntax. We&rsquo;ll also provide real-world examples of Linux sleep command use to help you understand how it works.<\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-what-does-the-linux-sleep-command-do-nbsp\"><strong>What does the Linux sleep command do?<\/strong><\/h2><p>The <strong>sleep<\/strong> command in Linux pauses command or script execution for a specific time. It is helpful for several tasks, such as:<\/p><ul class=\"wp-block-list\">\n<li><strong>Delaying execution <\/strong>&ndash; runs commands or bash scripts after the specified period. This ensures the requirements for running a process are met before its execution.&nbsp;<\/li>\n\n\n\n<li><strong>Minimize execution frequency &ndash; <\/strong>adds a delay to execute commands or scripts less frequently. This reduces the system or target service&rsquo;s load, which can otherwise cause performance issues.&nbsp;<\/li>\n\n\n\n<li><strong>Retrying a process <\/strong>&ndash; set up a retry mechanism that automatically reruns a script or command after a while instead of quitting the process immediately.&nbsp;<\/li>\n<\/ul><p>Typically, the Linux sleep command resides inside a script to add a delay between lines. However, as we&rsquo;ll demonstrate later, you can use it directly in your system&rsquo;s command-line interface.<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Linux-Commands-Cheat-Sheet.pdf\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/public\" alt=\"\" class=\"wp-image-69262\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-linux-sleep-command-syntax-and-options\"><strong>Linux sleep command syntax and options<\/strong><\/h2><p>The Linux sleep command syntax looks like this:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep number[suffix] [options]<\/pre><p>The <strong>number<\/strong> placeholder indicates the time duration, which can be a whole number or fractions written in decimals like <strong>1.5.<\/strong> You can use any number as long as it is bigger than <strong>0<\/strong>.<\/p><p>Meanwhile, <strong>[suffix]<\/strong> is the time unit represented by its first letter. The sleep command supports the following:<\/p><ul class=\"wp-block-list\">\n<li><strong>s<\/strong> &ndash; seconds&nbsp;<\/li>\n\n\n\n<li><strong>m<\/strong> &ndash; minutes<\/li>\n\n\n\n<li><strong>h<\/strong> &ndash; hours<\/li>\n\n\n\n<li><strong>d<\/strong> &ndash; days&nbsp;<\/li>\n\n\n\n<li><strong>inf <\/strong>&ndash; infinity<\/li>\n<\/ul><p>The suffix is optional. If you don&rsquo;t specify it, the sleep command will use seconds by default.<\/p><p>The Linux sleep command only supports these two options:<\/p><ul class=\"wp-block-list\">\n<li><strong>&ndash;help &ndash;<\/strong> shows the sleep command manual in your system&rsquo;s command-line interface.&nbsp;<\/li>\n\n\n\n<li><strong>&ndash;version<\/strong> &ndash; outputs the sleep command&rsquo;s version number, which is useful for checking if the command is installed and up-to-date.&nbsp;<\/li>\n<\/ul><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e008350f5d7\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" width=\"1460\" height=\"228\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/public\" alt=\"The sleep command version option's output\" class=\"wp-image-129228\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1460px) 100vw, 1460px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-linux-sleep-command-examples\"><strong>Linux sleep command examples<\/strong><\/h2><p>Let&rsquo;s explore how to use the sleep command in Linux. If you want to follow along, open your system&rsquo;s terminal or the <strong>browser terminal<\/strong> if you are a <a href=\"\/vps-hosting\">Hostinger virtual private server (VPS)<\/a> user.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\" id=\"h-using-suffixes-in-the-sleep-command\"><strong>Using suffixes in the sleep command<\/strong><\/h3><p>Suffixes in the sleep command attach directly to the end of the numbers. For example, this command will set a delay of two hours and 30 minutes:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 2h 30m<\/pre><p>Instead of using a time unit of longer duration, you can set a number higher than <strong>60<\/strong> or <strong>24<\/strong>. For example, you can use the following to set a one-day delay:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 24h<\/pre><p>If you omit the suffix, the command will automatically set a delay in seconds. For example, this will set sleep for 5 seconds:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 5<\/pre><h3 class=\"wp-block-heading\" id=\"h-specifying-fractional-seconds-in-the-sleep-command\"><strong>Specifying fractional seconds in the sleep command<\/strong><\/h3><p>Instead of specifying time fractions using more diminutive suffixes, use decimal numbers. For instance, use this command to set a 2-hour and 30-minute delay.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 2.5h<\/pre><p>This is especially useful if you want to set a pause in an increment of less than a second. For example, this will delay the command execution by 1.5 seconds:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 1.5<\/pre><h3 class=\"wp-block-heading\" id=\"h-using-sleep-in-bash-scripts\"><strong>Using sleep in bash scripts<\/strong><\/h3><p>The sleep command&rsquo;s common usage is to delay execution in shell scripts. For example, let&rsquo;s create a simple script that prints the message &ldquo;Hello&rdquo; and &ldquo;World&rdquo; after a brief pause. Here&rsquo;s how to do so:<\/p><ol class=\"wp-block-list\">\n<li>Create the bash script using this command:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano hello.sh<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Add the shebang in the first line to indicate that your file is a bash script:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Add the echo commands to print the message like so:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"Hello\"\n\necho \"World\"<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Add the sleep command between the two lines to set a delay like this:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"Hello\"\n\nsleep 5\n\necho \"World\"<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Press <strong>Ctrl + X<\/strong>, and <strong>Y<\/strong>, then <strong>Enter<\/strong> to save the script.<\/li>\n\n\n\n<li>Make the script executable by <a href=\"\/tutorials\/how-to-change-linux-permissions-and-owners\">changing the file permissions<\/a>:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">chmod +x hello.sh<\/pre><ol start=\"7\" class=\"wp-block-list\">\n<li>Run the script&nbsp; using this:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.\/hello.sh<\/pre><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0083510e47\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"932\" height=\"166\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-delays-echo-commands.png\/public\" alt=\"The Linux sleep command delays echo command execution\" class=\"wp-image-129230\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-delays-echo-commands.png\/w=932,fit=scale-down 932w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-delays-echo-commands.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-delays-echo-commands.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-delays-echo-commands.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 932px) 100vw, 932px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>While this is a basic example of using sleep in a bash script, the command&rsquo;s working principle remains the same regardless of the complexity of your script.<\/p><h3 class=\"wp-block-heading\" id=\"h-assigning-a-variable-to-the-sleep-duration\"><strong>Assigning a variable to the sleep duration<\/strong><\/h3><p>When working with a bash script, you can use a variable to dynamically set the sleep value. This is especially useful if you have multiple sleep commands and update their values often.<\/p><p>For example, this script has two sleep commands with explicit values, which you must change individually to update the delay duration.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"Hello\"\n\nsleep 5m\n\necho \"World\"\n\nsleep 5m\n\necho \"Linux is fun\"<\/pre><p>If you use a variable, the above script will look like the following. In this example, the sleep commands use <strong>$delay<\/strong> as the value, which we define as <strong>5m<\/strong>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#Define the value here\n\ndelay=\"5m\"\n\necho \"Hello\"\n\nsleep \"$delay\"\n\necho \"World\"\n\nsleep \"$delay\"\n\necho \"Linux is fun\"<\/pre><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Naming variables<\/h4>\n                    <p> You can use any name for your variable as long as it starts with the $ symbol.<\/p>\n                <\/div>\n\n\n\n<\/p><p>You can use multiple variables and values like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#Define the values here\n\ndelay1=\"5m\"\n\ndelay2=\"3m\"\n\necho \"Hello\"\n\nsleep \"$delay1\"\n\necho \"World\"\n\nsleep \"$delay2\"\n\necho \"Linux is fun\"<\/pre><p>Instead of writing the variables&rsquo; values inside the script, you can also pass them from the main shell when running the script. Note that this method will automatically assign the values to <strong>$number<\/strong> variables according to their order. Consider this example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.\/script.sh 60 20<\/pre><p>In the above command, we pass two values into the script: <strong>60 <\/strong>and <strong>20<\/strong>. By default, <strong>60 <\/strong>becomes the value of <strong>$1<\/strong>, while <strong>20 <\/strong>becomes the value of <strong>$2<\/strong>.<\/p><p>If you don&rsquo;t want to use <strong>$1<\/strong> or <strong>$2<\/strong> as variables in your script, you can reassign them to other variables. Here&rsquo;s an example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#Define the values here\n\ndelay1=\"$1\"\n\ndelay2=\"$2\"\n\necho \"Hello\"\n\nsleep \"$delay1\"\n\necho \"World\"\n\nsleep \"$delay2\"\n\nEcho \"Linux is fun\"<\/pre><p>This means <strong>$delay1<\/strong> will be <strong>60<\/strong>, while <strong>$delay2<\/strong> will be <strong>20<\/strong>.<\/p><div class=\"wp-block-image\">\n<figure data-wp-context='{\"imageId\":\"69e0083511895\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"818\" height=\"192\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-passed-variables.png\/public\" alt=\"The Linux command uses passed values for its variables\" class=\"wp-image-129231\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-passed-variables.png\/w=818,fit=scale-down 818w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-passed-variables.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-passed-variables.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-linux-sleep-command-passed-variables.png\/w=768,fit=scale-down 768w\" sizes=\"(max-width: 818px) 100vw, 818px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-setting-up-an-alarm-with-sleep\"><strong>Setting up an alarm with sleep<\/strong><\/h3><p>Ironically, the sleep command can be a tool for setting up a timed alert to wake you up. To do it, create a script that sends a notification and sound after a specific interval, similar to an alarm.<\/p><p>For this, you need the desktop version of Linux to show the notification and play the audio alert. Your alarm script might look like the following:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\n#Set the delay before the following commands start\n\nsleep \"$1\"\n\n#Send a notification\n\nnotify-send \"Alarm!\"\n\n#Play the alert sound. Replace with the actual path\n\npaplay \/path\/to\/audio.wav<\/pre><p>In this script, we use the sleep command with the &ldquo;<strong>$1<\/strong>&rdquo; variable so we can easily specify the delay during the execution. For example, use this command to set the alarm for five minutes from now:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">.\/alarm.sh 600<\/pre><h3 class=\"wp-block-heading\" id=\"h-delaying-commands-in-the-terminal\"><strong>Delaying commands in the terminal<\/strong><\/h3><p>Chained commands are a series of commands that run in order with a single execution. They are similar to lines in a bash script, except that they run directly from the command line.<\/p><p>Chaining commands requires operators to set the conditions for running them. For example, the double ampersands (<strong>&amp;&amp;<\/strong>) will start the second command only after the first one successfully runs.<\/p><p>Here&rsquo;s an example of chained commands that will print <strong>Hello<\/strong> and immediately follow it up with <strong>World<\/strong><\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"Hello\" &amp;&amp; echo \"World\"<\/pre><p>Like lines in a bash script, you can also use sleep to delay the execution of chained commands. Simply add sleep between the commands using an operator.<\/p><p>For instance, if you want the above command to output <strong>World<\/strong> 30 seconds after <strong>Hello<\/strong>, insert sleep like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"Hello\" &amp;&amp; sleep 30 &amp;&amp; echo \"World\"<\/pre><h3 class=\"wp-block-heading\" id=\"h-interrupting-sleep\"><strong>Interrupting sleep<\/strong><\/h3><p>To interrupt the sleep command, simply terminate the process by pressing <strong>Ctrl + C<\/strong>. This will stop the delay and the command or script execution.<\/p><p>For example, you run a command with a 3-minute delay like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sleep 3m &amp;&amp; echo \"Hello world\"<\/pre><p>If you hit <strong>Ctrl + C<\/strong>, the execution will stop, and you won&rsquo;t get any output even after three minutes. If you rerun the above command, you must wait a full three-minute delay for the output.<\/p><h3 class=\"wp-block-heading\" id=\"h-defining-check-intervals-with-sleep\"><strong>Defining check intervals with sleep<\/strong><\/h3><p>If you have looping scripts for regular system checks or monitoring, you can use the Linux sleep command to set the loop interval. While you can also use a <a href=\"\/tutorials\/cron-job\">cron job<\/a> to schedule a process, using sleep is better for more frequent tasks.<\/p><p>For example, here&rsquo;s a simple script that checks a service&rsquo;s status and prints a message if it is active.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nwhile true; do\n\n&nbsp;&nbsp;&nbsp;&nbsp;if systemctl is-active --quiet apache2; then\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo \"Apache is running.\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;else\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo \"Apache is not running.\"\n\n&nbsp;&nbsp;&nbsp;&nbsp;fi\n\n&nbsp;&nbsp;&nbsp;&nbsp;sleep 15&nbsp; # Wait 15 seconds before checking again\n\ndone<\/pre><p>Let&rsquo;s break down how this script works:<\/p><ol class=\"wp-block-list\">\n<li>The <strong>while-true<\/strong> statement will loop through the script until you explicitly stop it, creating a continuous process.&nbsp;<\/li>\n\n\n\n<li>The <strong>systemctl<\/strong> command checks if the Apache service is running.<\/li>\n\n\n\n<li>The conditional<strong> if-else<\/strong> statement gives different outputs based on the service status.&nbsp;<\/li>\n\n\n\n<li>The sleep command sets an interval, adding a 15-second delay before the script runs again.&nbsp;<\/li>\n<\/ol><h2 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h2><p>The sleep command pauses command or script execution for a specific time. It is helpful if you want to lower the execution frequency, add a delay to your process, or set up a retry mechanism.<\/p><p>To use the Linux sleep command, simply add the number and time unit, like <strong>sleep 2h 30s<\/strong>. You can use any number bigger than zero and decimals to set fractional time.<\/p><p>Commonly, the sleep command resides inside a bash script to add a pause between lines. However, you can also run it directly in your system&rsquo;s main shell to delay chained commands.<\/p><p>In a real-world scenario, you may use the sleep command to set up a notification system that will get triggered after a specific time. You can also use it inside a looped script to add delay for repetitive processes like monitoring.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Linux sleep command pauses script or command executions for a specific time. It is helpful to prevent your system [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/tutorials\/linux-sleep-command\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":121619,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to use the Linux sleep command","rank_math_description":"The Linux sleep command pauses script or command execution for a specified time. Learn its syntax, options, and practical uses in this guide.","rank_math_focus_keyword":"linux sleep command","footnotes":""},"categories":[22648,22644],"tags":[],"class_list":["post-129226","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/linux-sleep-command","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/linux-sleep-command","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/linux-sleep-command","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/linux-sleep-command","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/linux-sleep-command","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/linux-sleep-command","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/linux-sleep-command","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/linux-sleep-command","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/129226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/comments?post=129226"}],"version-history":[{"count":4,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/129226\/revisions"}],"predecessor-version":[{"id":138100,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/posts\/129226\/revisions\/138100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media\/121619"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/media?parent=129226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/categories?post=129226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/tutorials\/wp-json\/wp\/v2\/tags?post=129226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}