Linux 如何仅显示 wget 进度条?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4686464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:08:33  来源:igfitidea点击:

How to show wget progress bar only?

linuxbashwgetsh

提问by Flan Alflani

For example:

例如:

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

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 this

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

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

I know curl can do that, however i need to get wget to do that job.

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

采纳答案by Paused until further notice.

You can use the following filter:

您可以使用以下过滤器:

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
}

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 0x0d0x0a0x0d0x0a0x0dbeing sent right before the progress bar is started. This behavior may be implementation dependent.

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

回答by Paused until further notice.

This is another exemple, maybe will help you

这是另一个例子,也许会帮助你

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

回答by slva

You can use standard options:

您可以使用标准选项:

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

回答by Metaxal

You can use the followoption of tail:

您可以使用以下follow选项tail

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

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

+6是删除第6行。它可能因您的版本wget或语言而异。

You need to use --progress=bar:forceotherwise wget switches to the dottype.

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

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

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

回答by Lord Bo

Use:

用:

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

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

  • -q: 关闭wget输出

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

回答by ryenus

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.

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

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

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

# 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.

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

回答by Michael Shigorin

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

这不是字面上的答案,但这个片段也可能对一些来这里的人有帮助,例如“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

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).

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

回答by Philipp Kewisch

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:

这是一个解决方案,它将为您显示每个文件(或行,就此而言)的一个点。如果您使用--recursive. 这不会捕获错误,如果有额外的行,可能会稍微偏离,但对于许多文件的一般进展,它是有帮助的:

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

回答by Amir Khalili

Use using these flags:

使用这些标志:

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