watch usage

watch is a very useful command, almost all of the Linux distributions come with this gadget, as the name suggests, watch can help you monitor the operating results of a command, to save you manually run over and over again. Under Linux, watch the next periodic programs and full screen displays the result. You can take him to monitor changes in the results of all of the command you want, such as tail a log file, ls monitoring the change in size of a file, see your imagination !

1. Format:

watch [parameters] [command]

2. Function:

Command output may be output to the standard output device, used for periodic execution command / timing Run

3. Command parameters:

- n-default or --interval watch what program to run every 2 seconds , can be used to -interval -n or specified time interval .

-d or --differences display area changes with the -d --differences watch highlights or options .  The place -d = cumulative option will ever change (no matter that there are no recent change) have highlighted it .

-t -no-title or closes the top of the watch command time interval, command , it outputs the current time .

  -h, --help  help documentation

4. Example:

Examples 1:

Command: every second to highlight the network changes in the number of links

watch -n 1 -d netstat -ant Description:

Other operations: switching terminal: Ctrl + x exit watch: Ctrl + g

Example 2: one second highlight changes every few http link

command:

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

Description:

Every second to highlight changes in the number of http links. If the command back into contact with the pipe breaks, need to increase 'command Warping region.

Examples 3: view real-time connection simulated attack built up a client

command:

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

Description:

: Example 4 Monitoring the current directory  scf '  file changes

command:

watch -d 'ls -l|grep scf' 

 

Example : 5 average load of the output system 10 seconds

command:

watch -n 10 'cat /proc/loadavg'

Guess you like

Origin www.cnblogs.com/qingqing1/p/11329415.html