Linux Watch Command, To Monitor a Command Activity

Recently i came to know about watch command, from one of my friend when i have a different requirement. I got good benefit from watch command and i want to share with you people to get more benefit on it, when you have a problem on Linux system.

What’s watch command

Watch is a very powerful command-line tool which execute a program or commands or script at a regular intervals or repeatedly or periodically and displays the results on standard output in full screen, similar to top command.

By default, the program is run every 2 seconds. Add -n or --interval with watch command to specify a different interval, this interval is interpreted as the amount of time between the completion of one run of command and the beginning of the next run. It will not automatically exit, until you terminate it either by CTRL+C or kill the process.

Watch command comes in handy when you want to troubleshoot the issue by monitoring a command output continuously. It will monitor anything, not only command.

How to install watch in Linux

Watch command is available in default repository and installed by default. In case, if it’s not installed, use the distribution package manager and get installed.

How to use watch command in Linux

We are going to add few examples here, for better explanation about watch command, so that you can understand how to use in critical situations.

Free command have a option to get the output at a regular intervals but its not much good compare with top command. When we use Free with watch command, we can get the same kind of results, which will help us to dig the issue in detailed manner.

Exaample-1 Free command output with watch. Here we can get single output with regular interval.

cp command wont have option to show progress when coping data from one location to other. We can see the progress of copy command, when we combine a watch command with ls or du command on destination folder.

Exaample-5 First run the cp command and use ls or du command with watch to see the copy command progress.