如何只显示wget进度条?(How to show wget progress bar only?)
例如:
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我怎么能让它看起来像这样
downloading: TheFile.jpeg ... 25% [======> ] 614,424 173.62K/s ETA 00:14我知道curl可以做到这一点,但是我需要让wget做这个工作。
For example:
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:14How can i get it to look like this
downloading: TheFile.jpeg ... 25% [======> ] 614,424 173.62K/s ETA 00:14I know curl can do that, however i need to get wget to do that job.
最满意答案
您可以使用以下过滤器:
progressfilt () { local flag=false c count cr=$'\r' nl=$'\n' while IFS='' read -d '' -rn 1 c do if $flag then printf '%c' "$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序列。 这种行为可能取决于实现。
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 0x0d0x0a0x0d0x0a0x0d being sent right before the progress bar is started. This behavior may be implementation dependent.
更多推荐
发布评论