linux - 如何从 wget 输出中获取下载速度?

标签 linux command-line grep wget

我需要用 wget 下载几个文件并测量下载速度。

例如我用

下载
wget -O /dev/null http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs

输出是

--2010-10-11 18:56:00--  http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs
Resolving ftp.bit.nl... 213.136.12.213, 2001:7b8:3:37:20e:cff:fe4d:69ac
Connecting to ftp.bit.nl|213.136.12.213|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'

100%[==============================================================>] 1,474,560    481K/s   in 3.0s

2010-10-11 18:56:03 (481 KB/s) - `/dev/null' saved [1474560/1474560]

--2010-10-11 18:56:03--  http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs
Reusing existing connection to ftp.bit.nl:80.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'

100%[==============================================================>] 1,474,560    499K/s   in 2.9s

2010-10-11 18:56:06 (499 KB/s) - `/dev/null' saved [1474560/1474560]

FINISHED --2010-10-11 18:56:06--
Downloaded: 2 files, 2.8M in 5.9s (490 KB/s)

我需要 grep 总下载速度,即字符串 490 KB/s。 我该怎么做?

附言可能需要考虑到我们实际上只会下载一个文件的情况,因此不会有以 FINISHED

开头的最终输出

最佳答案

更新,一个使用 sed 的 grep 风格的版本:

wget ... 2>&1 | sed -n '$,$s/.*(\(.*\)).*/\1/p'

旧版本:

我想,下载后用文件大小除以下载时间更容易。 ;-)

(/usr/bin/time -p wget ... 2>&1 >/dev/null; ls -l newfile) | \
awk '
   NR==1 {t=$2};
   NR==4 {printf("rate=%f bytes/second\n", $5/t)}
'

awk 的第一行将“real xx.xx”经过的实际时间存储在变量t 中。 awk 的第二行将文件大小(ls -l 的第 5 列)除以时间并将其作为速率输出。

关于linux - 如何从 wget 输出中获取下载速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3909128/

相关文章:

linux - 显示 Docker 基础镜像中包含哪些内核功能的任何命令?

c - gdb 输出中的 <main+x> 是什么?

Java 运行时崩溃并出现 fatal error

bash - grep 管道内容中的文件内容

linux - Windows/Linux 子进程标准输入差异

macos - OS X : creating or extracting preview(. jpg,.png) 的 .eps 文件

linux - Unix/Linux 重定向和管道

java - 当我位于 Windows CMD 中的同一文件夹时,为什么必须为 .class 文件指定 Java 类路径?

linux - 删除第 N 个字段中编号小于 X 的行

linux - Grep:仅显示正则表达式组中匹配的内容