The sleep
command is used to delay the execution of the current action for a specified period of time. It is a simple yet useful command that can be used in scripts or in the terminal to pause a process for a specified amount of time.
Overview
The basic syntax for the sleep
command is as follows:
sleep [TIME]
Where TIME
is the number of seconds to delay the current action. For example, to pause for 5 seconds, you would use the following command:
sleep 5
You can also use fractions of a second by specifying a decimal value for TIME
. For example, to pause for half a second, you would use the following command:
sleep 0.5
Examples
Here are some examples of how the sleep
command can be used:
- To pause for 10 seconds before executing the next command:
sleep 10
- To pause for 2.5 seconds before executing the next command:
sleep 2.5
- To pause for 1 minute before executing the next command:
sleep 60
- To pause for 5 seconds and then echo a message:
sleep 5 && echo "Done sleeping!"
- To pause for 2 seconds and then run a script:
sleep 2; ./myscript.sh
Specific Use Cases
The sleep
command can be used in a variety of situations, such as:
- Delaying the execution of a script or command until a specific time.
- Pausing a script or command to allow for the completion of another process.
- Creating a timed loop in a script.
Options
The sleep
command has only one option:
Option | Description |
---|---|
-v | Verbose mode. Prints a message to standard error before pausing. |
Troubleshooting Tips
If the sleep
command does not seem to be working, double-check that you have specified the correct amount of time in seconds or fractions of a second. Also, make sure that you have not accidentally added any extra characters or spaces in the command.
Notes
- The
sleep
command is often used in conjunction with other commands or scripts to create more complex functionality. - The maximum value for
TIME
is dependent on the system’s timer resolution and may vary between systems.