Closed Captioning Closed captioning available on our YouTube channel

How to use the sleep command: 2-Minute Linux Tips

Network World | Sep 17, 2021

In this Linux tip, learn how to use the sleep command. The sleep command introduces a pause on the command line or in a script.

Copyright © 2021 IDG Communications, Inc.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the sleep command. The sleep command introduces a pause on the command line or in a script.
Say you want to watch whatever process is using the largest percentage of your CPU. You could keep repeating the command to display the information (even if you just used the up-arrow key to make the job easier) or you could let a script do the work for you and include a pause between each command so you can focus on the output. Here's an example.
In this script, we use the ps aux command to show the top CPU user and sleep 3 so that it runs only once every three seconds. The first ps aux line also displays the column headings.
Your output will look something like this:
In this case, the top CPU user is the gnome-shell. You can see that it's been running a long time, but is only using a small percentage of the CPU. This particular system is clearly not very busy.
The sleep command is generally used to pause for a number of seconds, but can pause for tenths of seconds or smaller (e.g., sleep .01), minutes (e.g., 10m), hours (e.g., 5h) or even days (e.g., 2d).
That’s your Linux tip for the sleep command.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.
Popular
Featured videos from IDG.tv