{"id":129226,"date":"2025-06-02T14:06:41","date_gmt":"2025-06-02T14:06:41","guid":{"rendered":"\/tutorials\/?p=129226"},"modified":"2026-03-10T09:26:23","modified_gmt":"2026-03-10T09:26:23","slug":"linux-sleep-command","status":"publish","type":"post","link":"\/ca\/tutorials\/linux-sleep-command\/","title":{"rendered":"Linux sleep command: Syntax, options, and examples"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><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<\/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 loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"566\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2022\/11\/Linux-cheat-sheet.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-69262\"  sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure>\n<\/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\"><figure data-wp-context='{\"imageId\":\"6a589c58cebed\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a589c58cebed\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" 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--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/06\/the-sleep-command-version-option.png\/w=1024,h=1024,fit=scale-down\" alt=\"The sleep command version option's output\" class=\"wp-image-129228\"  sizes=\"auto, (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--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=\"\/ca\/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=\"\/ca\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\"  sizes=\"auto, (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=\"\/ca\/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\"><figure data-wp-context='{\"imageId\":\"6a589c58d2782\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a589c58d2782\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" 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--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-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\"  sizes=\"auto, (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--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>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Naming variables                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> You can use any name for your variable as long as it starts with the $ symbol.<\/p>\n                    <\/div>\n        \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\"><figure data-wp-context='{\"imageId\":\"6a589c58d47db\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a589c58d47db\" class=\"aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" 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--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-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\"  sizes=\"auto, (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--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=\"\/ca\/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 from running a process too soon or too frequently while still keeping it automated. If you use bash scripts to automate intricate tasks in your Linux system, the sleep command can be a handy tool [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ca\/tutorials\/linux-sleep-command\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":0,"comment_status":"open","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":[22699],"tags":[],"class_list":["post-129226","post","type-post","status-publish","format-standard","hentry","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-GB","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\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/129226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/comments?post=129226"}],"version-history":[{"count":5,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/129226\/revisions"}],"predecessor-version":[{"id":140990,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/posts\/129226\/revisions\/140990"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/media?parent=129226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/categories?post=129226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ca\/tutorials\/wp-json\/wp\/v2\/tags?post=129226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}