View linux Nic traffic in real time and save the following script as an executable script file, for example, traff. sh. 1. This script allows you to customize the interface to be viewed, precise to decimal places, and flexibly display the unit according to the traffic volume. 2. The collection interval of this script is 1 second. 3. This script does not require additional software installation. You can handle it in case of urgent use. For example, you may want to see if there is any traffic passing through, or the approximate amount. 4. Some traffic viewing software may not be consistent with the value displayed in this script because of different computing precision. The display result of this script is slightly different from that of du meter. In addition, the transmission speed displayed by the transmission tool itself is not accurate. Usage: 1. Change chmod + x./traff. sh to an executable script. 2../traff. sh eth0 to start monitoring the interface eth0 traffic and press ctrl + c to exit. 01 #! /Bin/bash02while ["1"] 03do04eth = $105 RXpre = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $2}') 06 TXpre = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $10}') 07 sleep 108 RXnext = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $2}') 09 TXnext = $ (cat/proc/net/dev | grep $ eth | tr: "" | awk '{print $10}') 10clear11echo-e "\ t RX 'date + % k: % M: % s' TX "12RX =$ ($ {RXnext}-$ {RXpre}) 13TX =$ ($ {TXnext}-$ {TXpre })) 14 15if [[$ RX-lt 1024]; then16RX = "$ {RX} B/s" 17 elif [[$ RX-gt 1048576]; then18RX = $ (echo $ RX | awk '{print $1/1048576 "MB/s "}') 19else20RX = $ (echo $ RX | awk '{print $1/1024 "KB/s"}') 21fi22 23if [[$ TX-lt 1024]; then24TX = "$ {TX} B/s" 25 elif [[$ TX-gt 1048576]; then26TX = $ (echo $ TX | awk '{print $1/1048576 "MB/s "}') 27else28TX = $ (echo $ TX | awk '{print $1/1024 "KB/s"}') 29fi30 31 echo-e "$ eth \ t $ RX $ TX" 32 done