Sometimes you will need to delay for a specified time, pause for an amount of time specified by the sum of the values of the command line arguments. To get this done we can use sleep. The syntax is:
sleep NUMBER[suffix]
here, suffix are
s - seconds (default)
m - minutes
h - hours
d - days


NOTE: We we do not use any suffix then it automatically takes seconds as suffix.

Uses of sleep command:
Just imagine you have a script which copies files from any other server and they cannot be copied until they are downloaded fully. To achieve this you have to run a download process separately in different script. Now the scenario is that the copy script will continuously testing for the files whether they are downloaded or not results in high CPU usage.
Instead of this you can use sleep command and tests every 1 minutes whether all files are downlaoded or not then copies the file. It will not keep busy your CPU and results in good performence.

Examples:

To sleep for 10 seconds, use:
To sleep for 3 minutes, use:
To sleep for 6 hours, use:
To sleep for 4 days, use:
To sleep for .2 seconds:
To run commmand1, sleep for half minute and finally run command2:
command1 && sleep 30s && command2
To sleep in bash for loop:
for i in {1..5}
do
statements
statements
sleep 10s
done
To run while loop to display date and hostname on screen:
while [ : ]
do
clear
tput cup 5 5
date
tput cup 6 5
echo "Hostname : $(hostname)"
sleep 1
done
To check version of sleep:
sleep --version
It will shows the current version of sleep installed on the server.
Author
bhawanisingh
Views
1,800
First release
Last update
Rating
0.00 star(s) 0 ratings
Top