How to use the Linux sleep command

With the help of Linux sleep you can pause processes and let them run again afterwards. The command works under Linux and in combination with other commands and can be customised.

What is Linux sleep?

The Linux command sleep is used to pause a process for a specified period of time. How long this pause should last and whether operation is resumed or aborted afterwards is up to the user’s discretion. sleep is not only available in all common Linux distributions like Debian or Ubuntu and doesn’t have to be installed separately, but there’s also an equivalent in other operating systems The sleep command is a simple and useful tool particularly where shell scripts are to be paused.

How does the sleep command work?

The functionality of the Linux sleep command can be quickly explained. In addition to the actual command, you specify a duration and possibly a unit for the time. This is specified in seconds by default, but can also be added for minutes, hours or even days. The time value doesn’t have to be an integer, but can also be a floating point number. In this case, a point is used instead of a comma. Several sleep commands may be executed in succession. If you want to execute a subsequent command, use an AND operation (‘&&’). You’ll find an example of this below.

What is the syntax of the Linux sleep command?

The syntax of Linux sleep is as follows:

$ sleep [Number] [Suffix]
bash

sleep is always applied to the current process, unless you specify a different program.

What options and parameters does Linux sleep have?

There are only two options for the sleep command: ‘-h’ or ‘–help’ for information about sleep and ‘-v’ or ‘–version’ for information about version, license and development. However, you can specify the time unit yourself. The allowed parameters are:

  • s: The time is specified in seconds by default. When you omit the suffix, the numerical value will be calculated in seconds.
  • m: The time is specified in minutes.
  • h: The time is specified in hours.
  • d: The time is specified in days.

Examples of the Linux sleep command

Finally, to illustrate how Linus sleep works, we’ll show you a few examples of how it’s used.

$ sleep 60
bash

The current process will be paused for one minute (60 seconds) and then will continue to run.

$ sleep 2.5h
bash

The command pauses the current process for two and a half hours.

$ sleep 2m && killall libreoffice
bash

In conjunction with the Linux killall command, this terminates the LibreOffice program two minutes after executing sleep.

Was this article helpful?
Page top