Linux common commands: watch command


  watch is a very practical command, basically all Linux distributions come with this gadget, just like the name, watch can help you monitor the running result of a command, saving you from running it manually over and over again. Under Linux, watch executes the next program periodically and displays the execution result in full screen. You can use it to monitor the result changes of all commands you want, such as tail a log file, ls to monitor the size change of a certain file, see your imagination!

1. Command format:

  watch[parameter][command]

2. Command function:

  The output of the command can be output to the standard output device, which is mostly used for periodic execution of commands/timed execution of commands

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 time.

-d or --differences Watch with the -d or --differences option will highlight areas that change. The -d=cumulative option will highlight the places that have changed (regardless of the most recent change).

-t or -no-title will turn off the output of the watch command at the top of the interval, command, and current time.

-h, --help View help documentation

4. Example of use:

Example 1: Highlight changes in the number of network links every second

Order:

  watch -n 1 -d netstat -ant
description:

Other operations:
switch terminal: Ctrl+x
to exit watch: Ctrl+g

Example 2: Highlight the changes in the number of http links every second

Order:

  watch -n 1 -d 'pstree|grep http'

illustrate:

  Highlight changes in the number of http links every second. If the following command has a pipe character, you need to add '' to organize the command area.

Example 3: View the number of connections established by the simulated attack client in real time

Order:

  watch 'netstat -an | grep:21 | \ grep <IP of the simulated attack client>| wc -l' 

illustrate:

Example 4: Monitoring changes in scf' files in the current directory

Order:

  watch -d 'ls -l|grep scf' 

Example 5: The average load of the output system once every 10 seconds

Order:

  watch -n 10 'cat /proc/loadavg'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325188682&siteId=291194637