Watch — Command Line Tool To Monitor Real Time Stats In Linux

Tejas Udeshi
3 min readDec 28, 2020

During our day to day administration tasks in Linux, We often come across a situation where we have a need to monitor memory, disk space or some other vital stats in real time during production issues or while testing an application in Linux. Although we have a top command which can save our day, But there is another command line tool available known as “watch” which can help us to monitor stats/parameters in real time specific to our needs.

Let’s see the official one line description of watch on Linux(CentOS) Machine.

You can check the one liner description of any command by executing whatis <command name>

So it says watch executes a program periodically. Now lets check where is the actual binary location of the watch command.

We can check the actual location of the binary by executing type <command name>

To confirm whether it is an binary file we will make use of the file command and check the output. Remember to provide the full path of the watch binary file as shown below.

So it clearly says that it is an executable file with the version info and that it uses shared libraries.

Now Lets run the command and see how useful it is in our daily admin tasks.

Format : watch <command to be monitored> example: watch free -m

Now we have executed watch with free -m for monitoring. The first line indicates the interval after which the output of “free -m” will be refreshed. By default it is refreshed every 2 seconds. on the RHS it displays the date and time at which the command output was displayed.

You can see the difference in both the outputs.

Lets explore few more useful flags in watch command.

  • -t

t flag will not display the 1st line or the title which is seen above in the output.

watch -t free -m provides below output

  • n

With the help of n flag we can define the refresh interval which is 2 seconds by default.

watch -n 5 free -m

  • -d

It highlights the difference or the change in the output as compared to previous interval output

***The 2 snaps above has a difference of 2 minutes. It is just for illustration.

Similarly we can check disk space, uptime or execute any other command with watch to keep an eye on the output at regular intervals as per our needs.

Thanks for Reading!!!

--

--

Tejas Udeshi

6+ plus years of experience in IT. Currently working as an DevOps engineer. Eager to know more and learn about Linux, Cloud, Kubernetes and Cyber Security.