The watch command can help you monitor the running results of a command, saving you the need to manually run it over and over again. In Linux, watch periodically runs the next program and displays the execution result in full screen.
Watch is a very practical command. basically all Linux distributions have this tool. like a name, watch can help you monitor the running results of a command, saving you the need to run it manually over and over again. In Linux, watch periodically runs the next program and displays the execution result in full screen mode. You can use it to monitor the result changes of all the commands you want, such as tail a log file, ls to monitor the size changes of a file, and check your imagination!
1. command format:
Watch [Parameters] [commands]
2. command functions:
The output result of a command can be output to a standard output device, which is mostly used for periodical command execution/timed command execution.
3. command parameters:
-N or -- interval watch runs the program every 2 seconds by default. you can use-n or-interval to specify the interval.
-D or -- differences use-d or -- differences option watch to highlight the changed area. The "-d = cumulative" option will highlight the changed area (no matter whether there is a recent change.
-T or-no-title will close the time interval at the top of the watch command, command, and current time output.
-H, -- help
4. example:
Instance 1:
Command: The number of network connections is highlighted every second.
Copy codeThe code is as follows:
Watch-n 1-d netstat-ant
Note:
Other operations:
Switch terminal: Ctrl + x
Exit watch: Ctrl + g
Example 2: The number of http links is highlighted every second.
Command:
Copy codeThe code is as follows:
Watch-n 1-d 'pstree | grep http'
Note:
The number of http links is highlighted every second. If the following command carries a pipeline character, you need to add ''to normalize the command area.
Instance 3: view the number of connections established by the simulated attack client in real time
Command:
Copy codeThe code is as follows:
Watch 'netstat-an | grep: 21 | \ grep <模拟攻击客户机的ip> | Wc-L'
Note:
Example 4: monitor the changes in the files of the scf in the current directory
Command:
Copy codeThe code is as follows:
Watch-d 'ls-l | grep scf'
Average load of the system output once every 5 seconds for the instance
Command:
Copy codeThe code is as follows:
Watch-n 10 'cat/proc/loadavg'