Monitoring command outputs with watch
The watch command will execute a command at intervals and display that command's output. You can use a terminal session and the screen command described in chapter 10, Administration Calls to create a customized dashboard to monitor your systems with watch.
How to do it...
The watch
command monitors the output of a command on the terminal at regular intervals. The syntax of the watch
command is as follows:
$ watch COMMAND
Consider this example:
$ watch ls
Alternatively, it can be used like this:
$ watch 'df /home'
Consider the following example:
# list only directories $ watch 'ls -l | grep "^d"'
This command will update the output at a default interval of two seconds.
The -n SECONDS
option defines the time interval for updating the output:
# Monitor the output of ls -l every of 5 seconds $ watch -n 5 'ls -l'
There's more
The watch
command can be used with any command that generates output. Some commands change their output frequently, and the changes are...