Friday, May 3, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 503  / 2 Years ago, wed, june 1, 2022, 3:35:05

I can get total network usage from terminal by ifconfig wlp0s20f3 but i also get many other extra info about wlp0s20f3 device.


The output:


wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.43.67 netmask 255.255.255.0 broadcast 192.168.43.255
inet6 fe80::5f55:a45c:b66a:a7d2 prefixlen 64 scopeid 0x20<link>
ether 48:f1:7f:f3:15:83 txqueuelen 1000 (Ethernet)
RX packets 82724 bytes 108476705 (103.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28959 bytes 3840172 (3.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

I only need 103.4 MiB for rx and 3.6 MiB for tx to use together with command output plasmoid in kde panel. How can i get that?


PS: Any bash script to parse ifconfig output or any application gives that values are acceptable


More From » command-line

 Answers
4

  • The more obvious route is to use Grep to extract only the values.


    # RX bytes
    ifconfig wlp0s20f3 | grep -o '[0-9.]* MiB' | head -n1
    # TX bytes
    ifconfig wlp0s20f3 | grep -o '[0-9.]* MiB' | tail -n1


  • A more elegant alternative is to fetch the values (in bytes) from the /sys/class/net/wlp0s20f3/statistics/ directory.


    cat /sys/class/net/wlp0s20f3/statistics/rx_bytes
    cat /sys/class/net/wlp0s20f3/statistics/tx_bytes



[#2542] Friday, June 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
steaocyte

Total Points: 345
Total Questions: 122
Total Answers: 121

Location: Spain
Member since Wed, Nov 23, 2022
1 Year ago
steaocyte questions
;