How to show wget progress bar only?
例如:
1 2 3 4 5 6 7 8 9 | 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 |
我怎样才能使它看起来像这样
1 2 | downloading: TheFile.jpeg ... 25% [======> ] 614,424 173.62K/s ETA 00:14 |
我知道curl可以做到,但是我需要wget来完成这项工作。
使用:
1 | wget http://somesite.com/TheFile.jpeg -q --show-progress |
-
-q :关闭wget 的输出 -
--show-progress :强制wget 显示进度条,无论其详细程度设置为
您可以使用以下过滤器:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | progressfilt () { local flag=false c count cr=$'\ ' nl=$'\ ' 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 } |
用法:
1 2 3 4 | $ 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] |
此功能取决于在开始进度条之前立即发送的
使用以下标志进行使用:
1 | wget -q --show-progress --progress=bar:force 2>&1 |
其他人指出,选项
为了安全起见,我们首先要检查是否支持
1 2 3 4 5 | # set progress option accordingly wget --help | grep -q '\\--show-progress' && \\ _PROGRESS_OPT="-q --show-progress" || _PROGRESS_OPT="" wget $_PROGRESS_OPT ... |
也许是时候考虑只使用
您可以使用
1 | wget somesite.com/TheFile.jpeg --progress=bar:force 2>&1 | tail -f -n +6 |
您需要使用
不利的一面是刷新的频率比使用wget的频率低(看起来像每2秒刷新一次)。
您可以使用标准选项:
1 | wget --progress=bar http://somesite.com/TheFile.jpeg |
这是另一个示例,也许会对您有所帮助
1 2 3 4 5 6 7 | 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" } |
这里是一个解决方案,它将为您显示每个文件的点(或相应的行)。如果使用
1 2 3 | wget -r -nv https://example.com/files/ | \\ awk -v"ORS=" '{ print"."; fflush(); } END { print"\ " }' |
这不是字面上的答案,但此代码段也可能对某些来这里的人有所帮助,例如" zenity wget GUI":
' | stdbuf -i0 -o0 -e0 sed -rn 's/^.*\\<([0-9]+)%\\[.*$/\\1/p' | zenity --progress --auto-close
对我来说至关重要的是