Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can i print the output of vnstat -l to a file? what i've tried:

vnstat -l &> file

but it just hangsup

share|improve this question
up vote 2 down vote accepted

Remove the l option. From the vnstat man page:

   -l, --live mode
          Display current transfer rate for the selected interface in real time until interrupted. Statis‐
          tics  will be shown after interruption if the runtime was more than 10 seconds. An optional mode
          parameter can be used to select between the displaying of packets per second (mode 0) and trans‐
          fer  counters  (mode  1) during execution.  --style can also be used to affect the layout of the

So, the -l makes vnstat display output in "live mode", constantly updating, that's why you can't capture the output. If you want an easily parseable format use

vnstat --dumpdb

To just save the standard output do

vnstat > log.txt

If what you want is the current upload and download rate, vnstat is not the right tool for the job. Try sar from the sysstat package (see man sar for more info):

sudo apt-get install sysstat 
sudo sar -n DEV 1 1

To extract the current* download and upload rate for the interface wlan0 from sar's output do:

sudo sar -n DEV 1 1 | grep wlan0 | tail -n 1 | gawk '{print "Down: "$5,"Up: "$6}'

* What does "current" mean? sar (and any other method) will take some milliseconds to generate output.

share|improve this answer
but i actually need the total current network activity. this will print stats of today, yesterday, this month etc – teslasimus Mar 21 '13 at 14:14
What do you mean? What is "current" network activity? You mean the upload/download rate? – terdon Mar 21 '13 at 14:17
yes. upload/download... – teslasimus Mar 21 '13 at 14:33
See updated answer, vnstat is not the right tool for the job. – terdon Mar 21 '13 at 14:36

I don't know if you want to print just final summary to file from some period you are going to monitor network activity, but you can cheat it this way:

vnstat -l -i <device> >> dump.txt

The only issue is that vnstat will write output to file every second so it is not the most convenient way. For continuous monitoring with log for every second or so terdon answered your question.

share|improve this answer
Ok, but be aware of the problem that vnstat overwrites the status line again and again using backspaces so in the output you will se only the last status. You can replace the sequences of backspaces and expand the statuses to individual lines using for example: sed -re $'s/\b[\b ]+\b/\\n/g' dump.txt – pabouk Nov 20 '14 at 14:53
Tnak's for a good trick ;) – Michal Gonda Nov 22 '14 at 13:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.