Skip to content

Instantly share code, notes, and snippets.

@aznhe21
Created June 18, 2025 06:33
Show Gist options
  • Save aznhe21/5443082b99086d7dc51c918231be2b9e to your computer and use it in GitHub Desktop.
Save aznhe21/5443082b99086d7dc51c918231be2b9e to your computer and use it in GitHub Desktop.
Monitor network speed
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <interface>"
ls /sys/class/net
exit 1
fi
while true; do
rx1=$(cat "/sys/class/net/$1/statistics/rx_bytes")
tx1=$(cat "/sys/class/net/$1/statistics/tx_bytes")
sleep 1
rx2=$(cat "/sys/class/net/$1/statistics/rx_bytes")
tx2=$(cat "/sys/class/net/$1/statistics/tx_bytes")
printf "\r\e[KRX: %sB/s TX: %sB/s" "$(numfmt --to=iec $((rx2 - rx1)))" "$(numfmt --to=iec $((tx2 - tx1)))"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment