FactorPad
Faster Learning Tutorials

Linux sleep command summary with examples

sleep allows you to pause for a specified amount of time.
  1. Purpose - Learn what sleep is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with sleep.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 23, 2016
Updated: August 2, 2018
In this tutorial, 43 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / sleep command


The Linux sleep command

Beginner

Learn to pause shell scripts and processes at the Linux command line.

Video

Linux sleep command summary with examples (3:31)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our forty-third word, or command to memorize is sleep from our category System.

sleep allows you to pause for a specified amount of time.

Recall from the previous two videos we started to focus on time with the calendar, and now we'll discuss the timing of commands.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The sleep command has 2 options and arguments refer to the amount of time you'd like the system to pause.

Like most commands, help is available with double-dash --help. And the syntax for sleep goes like this, first is a number like 10, and next a timeframe like seconds, 10 seconds, or days, for 10 days.

The four timeframes are s for seconds, which is the default, m for minutes, h for hours and d for days. And even though it sounds fantastic, I wouldn't advise sleeping for longer than a day.

So why is sleep an important command? Well, you might like to automate an email, start a backup for just make it seem like you are in the office. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's hit sleep 3 and see what happens in 3, 2, 1.

$ sleep 3 $ _

Next, we'll try a sleep for 3 seconds again, except hit 33 by accident.

$ sleep 33 _

Uh oh, now what? Okay, always remember Ctrl-c will stop a process, and you will get your command prompt back.

$ sleep 33 ^C $ _

And last, let's stick with sleep 3 seconds again, but be more deliberate with s. Hit the ; which performs the second command after the first, and do an ls, wait another 2 seconds 2s and exit.

$ sleep 3s; ls; sleep 2s; exit stuff video16.txt video21.txt video26.txt video32.txt video35.txt video38a.txt video40.txt video05.txt video19.txt video23.txt video27.txt video33.txt video36.txt video38b.txt video11.txt video20.txt video24.txt video31.txt video34.txt video37.txt video38c.txt _

Very good, and as always exit closes the terminal window.

A Final Tip

Okay now you know how to use sleep. And you know the syntax for commands, options and arguments.

One last tip about the sleep command. So all joking aside, sleep can be really good for you, especially when we are about to learn about building scripts, soon in this Playlist.

Okay, thanks for visiting today. I hope this was a helpful introduction to the sleep command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

The timing for this tutorial is best understood with the video. Subscribe and check it out.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the cal command, hit Back.
  • To stick with the time theme and learn how to schedule jobs using the crontab command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / sleep command



 
 
Keywords:
linux sleep command
sleep linux
linux pause between processes
linux sleep examples
linux pause
wait linux
shell wait
shell sleep
linux pause for seconds
linux pause for minutes
linux wait
linux pause for hours
bash script sleep
linux sleep tutorial
linux pause for days
man sleep
linux pause scripts