Watch Command details for linux commands (monitoring command running results)

Source: Internet
Author: User
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'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.