Today I Learned
Search…
Monitor network (data) usage
The amount of data sent(uploaded) & received (downloaded) can be found out using the following bash script.
  • Only works per session, i.e stats are gathered once you power up your PC (or login).
  • Good to have if you have limited data avaiability & want to montior your data usage.
1
netu() {
2
# [net]work [u]sage: check network usage stats
3
​
4
net_device=$(route | awk '/default/ {print $8}')
5
TRANSMITTED=$(ifconfig "$net_device" | awk '/TX packets/ {print $6$7}')
6
RECEIVED=$(ifconfig "$net_device" | awk '/RX packets/ {print $6$7}')
7
​
8
pc_uptime=$(uptime -p | awk '{for (i=2; i<NF; i++) printf $i " "; if (NF >= 1) print $NF; }')
9
printf "%s\n\n" "Network Usage since $pc_uptime"
10
printf "%s\n" "$(tput bold)πŸ”Ό TRANSMITTED $(tput sgr0): $TRANSMITTED"
11
printf "%s\n" "$(tput bold)πŸ”½ RECEIVED $(tput sgr0): $RECEIVED"
12
}
Copied!

Demo

netu
​Grab it from here​
Copy link
Edit on GitHub
Contents
Demo