Download Speeds on Linux

System Speed Testing

For general speed tests of your connection from the command line, install the “speedtest-cli” python package via “pip”:

pip install speedtest-cli

Then simply run “speedtest-cli” from the command line.

Current Download Speeds

Because download speeds are a function of several factors, including the quality of your internet uplink, the speed of your local card and network, as well as the server at the other end of the connection, it can be useful to know how well current file transfer operations are performing.

There are several options for doing this. One option is to use an off-the-shelf tool like “iftop”

yum install iftop
iftop

Another way is to observe the change in bytes received or transmitted by looking at “/proc/net/dev”. You will need to know the name of the interface you’re interested in, but for most people that will be just one, and looking at /proc/net/dev should make it obvious the name of the active port. You can also run “ifconfig” to obtain this information. Output from:

cat /proc/net/dev

Looks something like this:

eno2: 746899204542 1020519735    0 427480  238     0          0  82978570 1964007160840 1389285911 

A bit messy for presentation, but the most relevant columns consist of the interface name followed by the bytes received. Look further down the row for the bytes transmitted.

By looking at the change in this file over time, you can determine the rate of received or transmitted bits in real time. It is easiest to create a little script that will do that for you. Here’s mine:

#!/bin/bash
#Computes download rate in MBs and Mbs for given interface
#John Johnston
#March 7, 2019
#Last Modified: 03/07/2019
usage()
{
echo
echo "Usage: $0 -i interface-name [-h]"
echo
}
process args
file= verbose= quiet= long=
while [ $# -gt 0 ]
do
case $1 in
-h) usage
;;
-i) INTERFACE=$2
shift
;;
--) shift
break
;;
-*) echo
echo $0: $1: unrecognized option >&2
echo "run ./downreceive.sh -h for usage" >&2
echo
;;
esac
shift
done
if [[ -z $INTERFACE ]]
then
echo
echo "You must provide the interface name. Run ifconfig if needed."
exit 1
fi
eth=($(cat /proc/net/dev | grep $INTERFACE))
if [[ -z $eth ]]
then
echo
echo "Interface provided is not valid"
exit 1
fi
receive1=($(cat /proc/net/dev | grep eno2 | cut -d " " -f 4))
sleep 2
receive2=($(cat /proc/net/dev | grep eno2 | cut -d " " -f 4))
rateMBs=echo "scale=2; (($receive2-$receive1) /2.0) * 0.000001" | bc -l
rateMbs=echo "scale=2; $rateMBs * 8" | bc -l
echo "Results:"
echo
echo $rateMBs "MBs"
echo $rateMbs "Mbs"
echo

Estimating Download Time

To estimate the time to download a file of a particular size to your system, try the Download Time Calculator.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.