Bash Sleep In Linux

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/bash-sleep-linux/
PINTEREST
PINTEREST
INSTAGRAM

Sleep is a function provided by bash shell to pause execution of commands. Using sleep function will make delay according to provided time values. There is also library support for sleep function in Linux environments.Simple usage of sleep function is like below.

Syntax

Syntax of the sleep function is very easy. We will just provide DELAY value to the function.

  • DELAY is time in seconds to wait but also minute hour or days can be specified related suffix which we will examine below.

Delay For 5 Seconds

We will create simple 5 seconds delay between mkdir and ls command

Here <strong>&amp;&amp; provides sequential execution.

Delay For 5 Seconds

Delay For 5 Seconds

We can also use this expression in a script line by line like below

By default given delay parameter to the sleep function is interpreted as seconds but we can change the interpretation by providing.

Sleep Specified Minutes

We can provide delay parameter as minute by providing mpostfix. In this example we will create 1 minute delay

Sleep Specified Hours

Hours delay can be specified like below. We will use h as prefix. Following example will wait for 1 hour before executing next command.

Sleep Specified Days

And the last one day can be specified like below. We will use d as prefix to specify day. Following example command will wait for 1 day.

Multiple Duration Expressions

Up to now we have looked single duration specification but sleep supports multiple duration specification. We can specify multiple values for sleep like 1 day 5 hours like below.

LEARN MORE  Brute Force Application Written In Java

Sleep Examples

Example Sleep Script

This is an example script that can be used for different purposes. Create filename sleepexample.sh and add following lines

Make script executable with chmod

And run

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/bash-sleep-linux/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

1 Response

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)