Linux sleep Command

Linux sleep command lets the terminal wait by the specified amount of time. By default, it takes time in seconds. But, we can set the delay time in minutes (m), hours (h), and days (d). It helps in pausing the execution of any particular command for a fixed amount of time.

Syntax:

Suffix may be 's,' 'm,' 'h,' 'd' for seconds, minutes, hours, or days respectively. And, the number is an integer; also, the number can be a floating-point number. If we specify two arguments, then it will pause the terminal for the sum of those number's amount of time.

Options:

The sleep command supports only two command line options, which are as follows:

--help: It is used to display the help manual.

--version: It is used to display the version information.

Examples of the sleep command

Let's see the following examples of the sleep command:

Default sleep command

The default sleep command will take time in seconds. Consider the below command:

The above command will pause the terminal for 5 seconds. Consider the below output:

Linux Sleep

Specify time in minutes

To specify the time in minute, use the 'm' argument with time. It will pause the terminal for the specified time in minutes. Consider below command:

The above command will pause the terminal for the given time. Consider the below output:

Linux Sleep

Specify time in hours

To specify the time in hour, use the 'h' argument with time. It will pause the terminal for the given amount of time. Consider below command:

The above command will pause the terminal for the given time. Consider the below output:

Linux Sleep

Specify time in days

To specify the time in days, use the 'd' argument with the time. It will pause the terminal for the given amount of time. However, it is useless to pause the terminal for days. Consider the below command:

The above command will pause the terminal for the given days. Consider the below output:

Linux Sleep

Exit from the sleep mode

To exit from the sleep mode, press "CTRL+C" keys. This key combination does exist, even if the terminal is on sleep mode. It will instantly take you out from the sleep mode.

Set an alarm using sleep

If we want to set a reminder for the specified amount of time. We can do this by using the sleep command as well. To do so, execute the sleep command with the specified amount of time and an audio or video file. Consider the below command:

the above command will play the specified audio file with Rhythmbox immediately after the execution of the command.

sleep with loop

The sleep command can be used for multiple purposes. Also, it can be used with loops. For example, the initial value of n =1, and we want to perform sleep operation for every incremented value of n. To do so, execute the below script:

The above script will execute the sleep command in the loop. Consider the below output:

Linux Sleep

Execute two commands after a time interval

Suppose, we want to execute two commands after a fixed time interval. We can do this by executing the sleep command as follows:

The above command will display the current working directory, and after two seconds, it will display the directory list. Consider the below output:

Linux Sleep
Next TopicLinux Time




Latest Courses