如何只显示wget进度条?

Fla*_*ani 64 linux bash wget sh

例如:

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
Run Code Online (Sandbox Code Playgroud)

我怎么能让它看起来像这样

downloading: TheFile.jpeg ...
25% [======>                              ] 614,424      173.62K/s    ETA 00:14
Run Code Online (Sandbox Code Playgroud)

我知道curl可以做到这一点,但是我需要得到wget才能做到这一点.

Lor*_* Bo 136

使用:

wget http://somesite.com/TheFile.jpeg -q --show-progress
Run Code Online (Sandbox Code Playgroud)

-q - 关闭Wget的输出

--show-progress - 强制wget以任何详细程度显示进度条

  • 对我来说,这显示了'wget:无法识别的选项' - show-progress'`?你知道这是否只出现在较新的wget版本中吗? (11认同)
  • @UliKöhler[该标志自1.16起仅存在](http://stackoverflow.com/a/32491843/1267663) (10认同)
  • 版本之间必须存在一些差异,但为了让它按照宣传的方式工作,对于版本1.19,我还需要添加以下选项:` - prog = bar:force:noscroll`,以及`-q`和`--show-progress`.这适用于构建中的Dockerfile. (8认同)

Pau*_*ce. 24

您可以使用以下过滤器:

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
}
Run Code Online (Sandbox Code Playgroud)

用法:

$ 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]
Run Code Online (Sandbox Code Playgroud)

此功能取决于在0x0d0x0a0x0d0x0a0x0d进度条启动之前发送的顺序.此行为可能取决于实现.


小智 12

使用以下标志来使用:

wget  -q --show-progress --progress=bar:force 2>&1
Run Code Online (Sandbox Code Playgroud)

  • 最好的单线。我不明白为什么这不是选择的答案。 (3认同)
  • 这是胜利者。这是 Stack Overflow 中的一个错误,它不是最佳答案。 (2认同)
  • @ MBT:“2>&1”简单地组合了stderr(通常用于错误和日志消息)和stdout(通常用于实际结果)输出。我猜这里是不必要的,但当人们想要将流程的完整输出(结果和错误消息)重定向到同一目标时,通常会使用它 (2认同)

rye*_*nus 11

该选件--show-progress,如被别人指出的那样,是最好的选择,但它仅适用,因为GNU wget的1.16,看在1.16的wget值得注意的变化.

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

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

wget $_PROGRESS_OPT ...
Run Code Online (Sandbox Code Playgroud)

也许是时候考虑使用了curl.


Met*_*xal 10

您可以使用以下follow选项tail:

wget somesite.com/TheFile.jpeg --progress=bar:force 2>&1 | tail -f -n +6
Run Code Online (Sandbox Code Playgroud)

+6是删除第6行.您的版本wget或语言可能有所不同.

您需要使用--progress=bar:force其他wget开关到该dot类型.

缺点是刷新的频率低于wget(看起来每2秒).该--sleep-interval的选项tail似乎只是将要的意思,但它并没有为我改变什么.