Linux – iftop – how to generate text file with its output

bashdebianiptableslinuxnetworking

iftop is great tool to view almost live bandwidth usage distinguished by source-ip source-port destination-ip destination port.

I'm using it to see which client's ip is using most bandwidth.
Now I would like to store output somewhere.

iftop uses ncurses so

iftop > log.txt

does not work as expected, result file is not readable.

Is there any tool like this which can be used to pipe output to a text file?

Best Answer

Since iftop-1.0pre3 (2014-01-01), a text output mode was added. This will be very useful to anyone trying to parse the output of iftop.

The command line option to activate text (batch) mode is:

-t          use text interface without ncurses

When using text mode, the following options are available:

-s num      print one single text output afer num seconds, then quit
-L num      number of lines to print

Use the -h option for help on iftop usage.

Example usage would be:

iftop -t > log.txt
iftop -t -s 180 > log.txt

If you want it to run in the background for 5 hours:

iftop -t -s 18000 > log.txt &

Check on background job with job command.