如何延迟wget进度条更新/刷新间隔?
默认情况下,它每毫秒更新一次,并且在作业脚本中运行时,每个更新都将作为单行捕获到 STDOUT 文件中,从而导致作业脚本 STDOUT 文件变大。我不想完全禁用进度条,因为我仍然想知道不同时间的进度。
wget
知道 --progress
选项,它允许您稍微调整输出设置。手册页摘录:
--progress=type
Select the type of the progress indicator you wish to use. Legal indicators are
"dot" and "bar".
[...]The "bar" indicator is used by default. It draws an ASCII progress bar graphics
(a.k.a "thermometer" display) indicating the status of retrieval. If the output is
not a TTY, the "dot" bar will be used by default.
Use --progress=dot to switch to the "dot" display. It traces the retrieval by
printing dots on the screen, each dot representing a fixed amount of downloaded data.
The progress type can also take one or more parameters. The parameters vary based on
the type selected. Parameters to type are passed by appending them to the type
sperated by a colon (:) like this: --progress=type:parameter1:parameter2.
When using the dotted retrieval, you may set the style by specifying the type as
dot:style. Different styles assign different meaning to one dot. With the "default"
style each dot represents 1K, there are ten dots in a cluster and 50 dots in a line.
The "binary" style has a more "computer"-like orientation---8K dots, 16-dots clusters
and 48 dots per line (which makes for 384K lines). The "mega" style is suitable for
downloading large files---each dot represents 64K retrieved, there are eight dots in
a cluster, and 48 dots on each line (so each line contains 3M). If "mega" is not
enough then you can use the "giga" style---each dot represents 1M retrieved, there
are eight dots in a cluster, and 32 dots on each line (so each line contains 32M).
With --progress=bar, there are currently two possible parameters, force and noscroll.
When the output is not a TTY, the progress bar always falls back to "dot", even if
--progress=bar was passed to Wget during invokation. This behaviour can be overridden
and the "bar" output forced by using the "force" parameter as --progress=bar:force.
By default, the bar style progress bar scroll the name of the file from left to right
for the file being downloaded if the filename exceeds the maximum length allotted for
its display. In certain cases, such as with --progress=bar:force, one may not want
the scrolling filename in the progress bar. By passing the "noscroll" parameter,
Wget can be forced to display as much of the filename as possible without scrolling
through it.
Note that you can set the default style using the "progress" command in .wgetrc.
That setting may be overridden from the command line. For example, to force the bar
output without scrolling, use --progress=bar:force:noscroll
我建议阅读整篇文章以了解
wget
的进度表如何工作,但简而言之,以下是要点:
wget
将使用 dot
显示方法dot
显示方法每下载 X 个字节数就会显示一个 .
--progress=dot:<style>
传递给 wget
调用来调整style
可以是以下之一:
default
:每点 1KBbinary
:每点 8KBmega
:每点 64KBgiga:
每点 1MB总而言之,为了减少下载大文件时的输出,您可以按如下方式调用 wget:
$> wget --progress=dot:mega <url>
这是一个很老的问题,但我有另一个解决方案。您可以使用 awk 来过滤输出:
wget https://some.large.file -O file.bin 2>&1 | awk 'BEGIN{t=0;l=""}systime()-t>1{print $0;t=systime()}/.+/{l=$0}END{print l}'
让我们解释一下: