sleep Command in Linux with Examples

Posted in

sleep Command in Linux with Examples

Sangeeta Gulia
Last updated on October 20, 2022

    Pausing a terminal can be useful for performing debugging and scheduling related tasks. This can be done using the sleep command in Linux. We will discuss various suffixes available with the sleep command in this article.

    What is the sleep command?

    We use the sleep command to pause the terminal for a specified period of time or create a dummy task for a given time. Due to the construction of a dummy task, the execution is delayed. By default, it measures time in seconds, but a minor suffix(s, m, h, d) may be added at the end to convert it to any other format. This command puts a timer on the execution of shell scripts or commands. This command stops the execution for the length of time specified.

    So basically, what the sleep command does is that it allows you to postpone anything for a set length of time. You can put the calling shell script on hold for a set amount of time. Pause for 5 seconds or suspend execution for 2 minutes, for example.

    To put it another way, the sleep command takes a break from the execution of the following shell command for a certain amount of time. Additional parameters are available in the GNU version of the sleep command.

    For example, use sleep to suspend a bash shell script or command prompt for five seconds. Scheduling tasks and postponing execution to allow a process to start are two common instances of sleep instructions. Another option is to wait for a wifi network connection to become available before streaming a huge file over the network.

    The syntax of the sleep command is:

    sleep NUMBER[SUFFIX]...

    Examples of using the sleep command

    Wait for 5 seconds before performing a task

    $ sleep 5

    Wait for 5 minutes before performing a task

    $ sleep 5m

    Wait for 5 hours before performing a task

    $ sleep 5h

    Conclusion

    In this article, we went through the description of the sleep command of Linux. This command pauses the execution of tasks by creating dummy tasks. It allows us to specify options like m, h, d for pausing the execution for a specified number of minutes, hours, or days, respectively.

    People are also reading:

    Tags:
    linux command

    Leave a Comment on this Post

    0 Comments