How can I get an interface's bandwidth at any given second from the Linux command line?
Solution 1:
The number of bytes sent and received by eth0
since the interface was brought up can be read in /sys/class/net/eth0/statistics/tx_bytes
and /sys/class/net/eth0/statistics/rx_bytes
respectively. The number of packets can be read in …/tx_packets
and …/rx_packets
. If you have an older kernel that doesn't provide these files, the data is available in the output of /sbin/ifconfig eth0
.