Many a times, one needs to keep an eye on certain aspects of a system. Be it verifying transfer of contents over to a host or scanning log files as they are written to, these tasks need constant supervision. Wouldn’t it be better if there was some automation to accomplish this? Thankfully, there is one.

Most Linux distros have an inbuilt utility known as ‘watch’ which essentially keeps running a particular command, every ‘n’ number of seconds. The watch command is very simple to use.

Recently, I was rendering a video in Openshot. To my inconvenience, the progress bar within the Openshot failed to show any visual indication. Here I quickly fired up a console & navigated to the location where my video file was to be rendered by Openshot. After this, it was simply a matter of running the mundane ‘ls -lhtr’ command using watch. The ‘ls -lhtr’ lists the files by their recent modification times & presents them in human readable size output. I used the following format;

$watch -n 5 ls -lhtr

Watch Command

Here the ‘-n 5’ option tells watch to run the command ‘ls -lhtr’ every five seconds. One can notice the increasing file size of the file which was rendered by Openshot as the command ran at five seconds interval. Thus, I was guaranteed of Openshot doing its work smoothly despite the conked progress bar in GUI.

The ‘watch’ command is regularly used by system administrators to check the output of a log file as it is written to viz. apache access log. Of-course, one can even use the ‘tail -f’ command to check the output of the log file in this scenario. Watch is a nifty tool in any administrators toolbox and its utility is limited by your imagination.

Advertisements