如何仅显示 wget 进度条?

新手上路,请多包涵

例如:

 wget http://somesite.com/TheFile.jpeg

    downloading: TheFile.tar.gz ...
    --09:30:42--  http://somesite.com/TheFile.jpeg
               => `/home/me/Downloads/TheFile.jpeg'
    Resolving somesite.co... xxx.xxx.xxx.xxx.
    Connecting to somesite.co|xxx.xxx.xxx.xxx|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1,614,820 (1.5M) [image/jpeg]

    25% [======>                              ] 614,424      173.62K/s    ETA 00:14

How can I get it to look like the following?

    downloading: TheFile.jpeg ...
    25% [======>                              ] 614,424      173.62K/s    ETA 00:14

我知道 curl 可以做到这一点。但是,我需要让 wget 来完成这项工作。

原文由 Flan Alflani 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.7k
2 个回答

您可以使用以下过滤器:

 progressfilt ()
{
    local flag=false c count cr=$'\r' nl=$'\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
}

用法:

 $ 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 。此行为可能取决于实现。

原文由 Dennis Williamson 发布,翻译遵循 CC BY-SA 4.0 许可协议

利用:

 wget http://somesite.com/TheFile.jpeg -q --show-progress

  • -q :关闭 wget 的输出

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

原文由 Lord Bo 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题