How to track internet usage (upload & download) on Linux?

Install vnstat, it gives logs the usage on a network interface and you can display the usage over different time periods.

Here's the default output from my system

                  rx      /      tx      /     total    /   estimated
eth0:
   Jun '13     14.40 GiB  /    1.70 GiB  /   16.10 GiB
   Jul '13      3.57 GiB  /    2.55 GiB  /    6.12 GiB  /   40.44 GiB
 yesterday    968.58 MiB  /    2.26 GiB  /    3.21 GiB
     today    377.88 MiB  /   26.73 MiB  /  404.61 MiB  /     582 MiB

If you get vnstati as well, you can display the data in different ways e.g.

Usage graph


Easiest to use and easiest to control output and redirect to file for continuous logging:

ifstat

Probably comes with most linux distributions, and can be installed with brew on mac. Highly recommended.


vnstat is probably the best way to do this. It can be installed using the following command in terminal:

sudo apt-get install vnstat

If you don't want to keep checking the data usage status every time then use:

watch -n 5 --differences vnstat -d eth0

It would display the status every 5 seconds in the open terminal with the differences that occur in the values. -d is used to display the status of each day and eth0 is the ethernet used for internet connection (wlan0 may be used for WiFi).