The Linux watch command is a nifty little tool that can be used when you want to keep the result of a command under constant watch.
Here’s a sample for watching the /proc/mdstat file.
watch -n1 cat /proc/mdstat
The “-n1“-switch tells watch to refresh every “1” second (“-n2” would consequently mean, “refresh every 2 seconds” and so on).
The “cat /proc/mdstat” is the command to keep an eye on. “/proc/mdstat” is a process file that displays the state of md-raid drives in the system.
Press “ctrl-C” to stop the running command.
This is an example of “watching” the free memory:
watch -n1 free -m
If you add the “-d” switch, watch will mark differences between the runs.
watch -d -n1 free -m
And with the “-d=cumulative” switch the differences will be marked cumulatively between runs:
watch -d=cumulative -n1 free -m
You may also watch for directory changes:
watch -d ls -l
If you do not specify a watch interval (using “-n“) the default is set to 2 seconds.
For more info, see the manual pages for the watch command.
For watching files see the related “tail” command.