如何只显示 wget 进度条?

发布于 2024-10-11 15:02:37 字数 1817 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

能怎样 2024-10-18 15:02:37

使用:

wget http://somesite.com/TheFile.jpeg -q --show-progress
  • -q:关闭wget的输出

  • --show-progress:强制 wget 显示进度条,无论其详细级别设置为多少

Use:

wget http://somesite.com/TheFile.jpeg -q --show-progress
  • -q: Turn off wget's output

  • --show-progress: Force wget to display the progress bar no matter what its verbosity level is set to

听你说爱我 2024-10-18 15:02:37

使用这些标志运行:

wget -q --show-progress --progress=bar:force 2>&1

Run using these flags:

wget -q --show-progress --progress=bar:force 2>&1
雾里花 2024-10-18 15:02:37

您可以使用以下过滤器:

progressfilt ()
{
    local flag=false c count cr=

用法:

$ wget --progress=bar:force http://somesite.com/TheFile.jpeg 2>&1 | progressfilt
100%[======================================>] 15,790      48.8K/s   in 0.3s

2011-01-13 22:09:59 (48.8 KB/s) - 'TheFile.jpeg' saved [15790/15790]

此函数取决于在进度条启动之前发送的 0x0d0x0a0x0d0x0a0x0d 序列。此行为可能依赖于实现。

\r' nl=

用法:


此函数取决于在进度条启动之前发送的 0x0d0x0a0x0d0x0a0x0d 序列。此行为可能依赖于实现。

\n' while IFS='' read -d '' -rn 1 c do if $flag then printf '%s' "$c" else if [[ $c != $cr && $c != $nl ]] then count=0 else ((count++)) if ((count > 1)) then flag=true fi fi fi done }

用法:

此函数取决于在进度条启动之前发送的 0x0d0x0a0x0d0x0a0x0d 序列。此行为可能依赖于实现。

You can use the following filter:

progressfilt ()
{
    local flag=false c count cr=

Usage:

$ wget --progress=bar:force http://somesite.com/TheFile.jpeg 2>&1 | progressfilt
100%[======================================>] 15,790      48.8K/s   in 0.3s

2011-01-13 22:09:59 (48.8 KB/s) - 'TheFile.jpeg' saved [15790/15790]

This function depends on a sequence of 0x0d0x0a0x0d0x0a0x0d being sent right before the progress bar is started. This behavior may be implementation dependent.

\r' nl=

Usage:


This function depends on a sequence of 0x0d0x0a0x0d0x0a0x0d being sent right before the progress bar is started. This behavior may be implementation dependent.

\n' while IFS='' read -d '' -rn 1 c do if $flag then printf '%s' "$c" else if [[ $c != $cr && $c != $nl ]] then count=0 else ((count++)) if ((count > 1)) then flag=true fi fi fi done }

Usage:

This function depends on a sequence of 0x0d0x0a0x0d0x0a0x0d being sent right before the progress bar is started. This behavior may be implementation dependent.

小巷里的女流氓 2024-10-18 15:02:37

可以使用tailfollow选项:

wget somesite.com/TheFile.jpeg --progress=bar:force 2>&1 | tail -f -n +6

+6是删除前6行。根据您的 wget 版本或您的语言,它可能会有所不同。

您需要使用 --progress=bar:force 否则 wget 会切换到 dot 类型。

缺点是刷新频率比 wget 低(看起来每 2 秒刷新一次)。 tail--sleep-interval 选项似乎就是为了这个目的,但它对我来说没有任何改变。

You can use the follow option of tail:

wget somesite.com/TheFile.jpeg --progress=bar:force 2>&1 | tail -f -n +6

The +6 is to delete the first 6 lines. It may be different on your version of wget or your language.

You need to use --progress=bar:force otherwise wget switches to the dot type.

The downside is that the refreshing is less frequent than with wget (looks like every 2 seconds). The --sleep-interval option of tail seems to be meant just for that, but it didn't change anything for me.

梦回旧景 2024-10-18 15:02:37

正如其他人指出的那样,选项 --show-progress 是最好的选项,但它仅从 GNU wget 1.16 开始可用,请参阅 wget 1.16 中值得注意的变化

为了安全起见,我们可以首先检查是否支持 --show-progress

# set progress option accordingly
wget --help | grep -q '\--show-progress' && \
  _PROGRESS_OPT="-q --show-progress" || _PROGRESS_OPT=""

wget $_PROGRESS_OPT ...

也许是时候考虑只使用 curl 了。

The option --show-progress, as pointed out by others, is the best option, but it is available only since GNU wget 1.16, see Noteworthy changes in wget 1.16.

To be safe, we can first check if --show-progress is supported:

# set progress option accordingly
wget --help | grep -q '\--show-progress' && \
  _PROGRESS_OPT="-q --show-progress" || _PROGRESS_OPT=""

wget $_PROGRESS_OPT ...

Maybe it's time to consider just using curl.

败给现实 2024-10-18 15:02:37

您可以使用标准选项:

wget --progress=bar http://somesite.com/TheFile.jpeg

You can use standard options:

wget --progress=bar http://somesite.com/TheFile.jpeg
挽梦忆笙歌 2024-10-18 15:02:37

这是另一个例子:

download() {
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}

This is another example:

download() {
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    echo -ne "\b\b\b\b"
    echo " DONE"
}
ㄟ。诗瑗 2024-10-18 15:02:37

这是一个解决方案,它将为每个文件(或行,就此而言)显示一个点。如果您使用 --recursive 下载,它特别有用。这不会捕获错误,如果有额外的行,可能会略有偏差,但对于许多文件的总体进展来说,它是有帮助的:

wget -r -nv https://example.com/files/ | \
    awk -v "ORS=" '{ print "."; fflush(); } END { print "\n" }'

Here is a solution that will show you a dot for each file (or line, for that matter). It is particularly useful if you are downloading with --recursive. This won't catch errors and may be slightly off if there are extra lines, but for general progress on a lot of files it is helpful:

wget -r -nv https://example.com/files/ | \
    awk -v "ORS=" '{ print "."; fflush(); } END { print "\n" }'
路弥 2024-10-18 15:02:37

这并不是字面上的答案,但此代码片段可能对一些来这里的人有帮助,例如“zenity wget GUI”:

LANG=C wget -O /dev/null --progress=bar:force:noscroll --limit -速率 5k http://nightly.altlinux.org/sisyphus/ChangeLog 2>&1 | stdbuf -i0 -o0 -e0 tr '>' '\n' | stdbuf -i0 -o0 -e0 sed -rn 's/^.*\<([0-9]+)%\[.*$/\1/p'| zenity --progress --auto-close

对我来说至关重要的是 stdbuf(1)

This is not literally an answer but this snippet might also be helpful to some coming here for e.g. "zenity wget GUI":

LANG=C wget -O /dev/null --progress=bar:force:noscroll --limit-rate 5k http://nightly.altlinux.org/sisyphus/ChangeLog 2>&1 | stdbuf -i0 -o0 -e0 tr '>' '\n' | stdbuf -i0 -o0 -e0 sed -rn 's/^.*\<([0-9]+)%\[.*$/\1/p' | zenity --progress --auto-close

What was crucial for me is stdbuf(1).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文