Use of the Linux watch command
1. Command brief
The watch command executes a given command in a periodic manner and displays the execution results in full screen.
watch is a very useful command that is included in almost all Linux distributions. As the name suggests, watch helps monitor the results of a command, saving us from running it manually over and over again. For example, tail a log file, ls monitors the size change of a file, etc. The default is to run the program every 2 seconds. You can specify the interval with-n or--interval.
2. command format
watch [OPTIONS] COMMAND
3. option descriptions
-d, --differences [PERMANENT] Highlight differences between the last two updates. - The d cumulative option highlights all changes (regardless of the most recent)-n, --interval SECONDS Specifies the monitoring interval in seconds. default 2s, not less than 0.1s-p, --precise attempts to perform a command exactly at the specified interval Watch-t, --no-title close watch command time interval at top, command, output at current time-b, --beep monitored command exit code non-zero Beep-e, --errexit watch stops updating when monitored command error occurs and exits after key press-g, --chgexit exit watch-c when monitored command output changes, --color interprets ANSI color and style sequences-x, --exec passes commands to exec(2) instead of sh -c-h, --help displays help information and exits-v, --version displays version information and exits
4. Common examples
(1) Repeatedly execute the uptime command, which is executed every 2 seconds by default.
watch uptime
(2) Check the current directory file log changes.
watch -d "ls -l | grep log"
Note that when monitoring commands contain pipes, you need to enclose them in quotation marks.
(3) Check the average load of the system every 10s.
watch -n10 cat /proc/loadavg
(4) Highlight changes in the number of network connections every 1s.
watch -n1 -d netstat -ant
references
[1] watch(1) manual
The above is all the content of this article, I hope to help everyone's study, but also hope that everyone a lot of support.