Watch ifconfig command (monitor network status every two seconds)

Time:2019-4-20

The watch command can execute a command repeatedly, with a default time interval of 2 seconds.

Watchifconfig can monitor network status every two seconds.
Watch-d ifconfig can monitor network status every two seconds and mark the changed parts
Watch-d ifconfig eth0 can monitor eth0 only every two seconds and mark the changed part.
Watch-d’ifconfig eth0 | grep bytes’can monitor eth0 only every second, show only the traffic part, and mark the changed part.

Watch can also be used to view changes in files, such as:
For example, watch ls-la file, which means two seconds to see how file size changes in file1.

Exit: Ctrl + C

Examples of watch commands

Watch is a very useful command. Basically all Linux distributions come with this widget. Like the name, watch can help you monitor the results of a command and save you from running it manually over and over again. Under Linux, watch is the next program that executes periodically and displays the results of execution on a full screen. You can use it to monitor the results of all the commands you want, such as tail a log file, ls to monitor the size of a file, see your imagination!

1. Command format

Watch [parameter] [command]

2. Command Function

The output results of commands can be output to standard output devices, mostly for periodic execution of commands/timing execution of commands.

3. Command parameters

– N or — interval watch runs the program every 2 seconds by default, and you can use – N or – interval to specify the interval time.
– D or – differences highlights the changed area with the – D or – differences option watch. The – D = cumulative option highlights the changes (whether or not they have changed in the latest one).
– t or – no – Title closes the time interval at the top of the watch command, the command, and the output of the current time.
– h, – help to view help documents

4. Use examples

Example 1:

Command: Highlight changes in the number of network links every second

watch -n 1 -d netstat -ant

Output results:

Every 1.0s: netstat -ant Mon Feb 27 20:49:38 2017

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.0.210:22 192.168.0.5:51577 ESTABLISHED
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN

Description: Other operations:
Handover terminal: Ctrl + X
Exit watch: Ctrl + G

Example 2: Highlighting the number of HTTP links every second

Order:

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

Explain:
Highlight the number of HTTP links every second. If the following command has a pipe character, you need to add”to reorganize the command area.

Example 3: Real-time view of the number of connections established by simulated attack clients

Order:

Watch'netstat-an | grep: 21 | grep < client IP > | wc-l'

Example 4: Monitoring changes in scf’s files in the current directory

Order:

watch -d 'ls -l|grep scf'
 

Example 5:10 second output system average load

Order:

watch -n 10 'cat /proc/loadavg'

The output results are as follows:

Every 10.0s: cat /proc/loadavg Mon Feb 27 20:54:45 2017

0.01 0.04 0.05 1/132 6335

Recommended Today

PHP 12th week function learning record

sha1() effect sha1()Function to evaluate the value of a stringSHA-1Hash. usage sha1(string,raw) case <?php $str = “Hello”; echo sha1($str); ?> result f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 sha1_file() effect sha1_file()Function calculation fileSHA-1Hash. usage sha1_file(file,raw) case <?php $filename = “test.txt”; $sha1file = sha1_file($filename); echo $sha1file; ?> result aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d similar_text() effect similar_text()Function to calculate the similarity between two strings. usage similar_text(string1,string2,percent) case […]