109

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:14

How can I get it to look like the following?

    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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Flan Alflani
  • 2,065
  • 3
  • 15
  • 17
  • 1
    I don't think this is possible without writing a script to parse wget's output. `wget -nv` is about the closest you are going to get, and it doesn't actually display a progress bar, just a one-line summary when the download completes. – cdhowie Jan 13 '11 at 23:33
  • 3
    wget --progress=bar:force:noscroll – Leo Gallucci Apr 03 '18 at 13:01
  • 2
    `curl` can download files and produce a simple progress bar: `echo "downloading: $file ..." && curl --progress-bar --remote-name --location "$url"` – curusarn Dec 15 '19 at 22:18

9 Answers9

239

Use:

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

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

Michael
  • 8,362
  • 6
  • 61
  • 88
Lord Bo
  • 3,152
  • 3
  • 15
  • 22
  • 13
    For me this shows `wget: unrecognized option '--show-progress'` ? Do you know if this is only present in newer wget versions? – Uli Köhler May 29 '15 at 13:40
  • 10
    @UliKöhler [the flag only exists since 1.16](http://stackoverflow.com/a/32491843/1267663) – Whymarrh Dec 12 '15 at 01:36
  • 14
    There must be some difference in between versions, but to get it to work as advertised, for version 1.19, I also need to add following option: `--progress=bar:force:noscroll`, together with the `-q` and `--show-progress`. This works nicely for a Dockerfile within a build. – YoYo Apr 23 '18 at 04:21
  • 1
    As @YoYo mentions, don't forget the `--progress=bar:force:noscroll` to stop the newlines from being generated! – Brent Faust Aug 11 '18 at 00:03
33

Run using these flags:

wget -q --show-progress --progress=bar:force 2>&1
Plasma
  • 105
  • 1
  • 6
Amir Khalili
  • 331
  • 3
  • 2
  • 2
    Best one-liner. I don't understand why it's not the chosen answer. – Salamandar Apr 28 '19 at 16:15
  • What does `force 2>&1` do? Just `wget -q --show-progress --progress=bar` seems to yield to the same output for me. – MBT Aug 29 '19 at 11:48
  • 2
    This one is the winner. It's a bug in Stack Overflow that it is not the top answer. – mmla Nov 04 '19 at 06:07
  • 2
    @ MBT: "2>&1" simply combines stderr (usually meant for error and log messages) and stdout (usually meant for actual results) outputs. Guess it is unnecessary here, but often it is used when people want to redirect the complete output of a process (results AND error messages) to the same target – jov14 Dec 10 '20 at 12:43
32

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • If you don't have at least version 1.16 of wget this is usefull ! – user2226755 Feb 01 '19 at 21:54
  • 1
    To prevent bug with char-encoding, you have to replace `%c` by `%s` to fix this : `�` – user2226755 Feb 01 '19 at 22:02
  • @HorsSujet: The ones I see are from Unicode left and right single quotation marks. I'll edit my answer to make the change. Thanks for the report. – Dennis Williamson Feb 01 '19 at 22:12
  • You can also improve your code with 2nd function, it's more readable : https://pastebin.com/Ek5Wf4XK – user2226755 Feb 01 '19 at 22:30
  • I agree that's useful in a full script, but I don't think it's necessary for the answer. – Dennis Williamson Feb 01 '19 at 22:36
  • can i achive this while `wget` works on the backgorund? – alper Aug 30 '20 at 17:19
  • 1
    @alper: If you background a program its output will wind up being intermingled into other output unless you redirect it to a file. If you do that, the type will default to `dot` and you can set the scale to your liking. Example (with explicitly setting the type): `wget --progress=dot:giga URL > progressfile.txt &`. Then you can periodically examine the file to see how far along it is. Perhaps `wc -l progressfile.txt` – Dennis Williamson Jun 28 '22 at 15:32
13

You can use the follow option of tail:

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

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

You need to use --progress=bar:force otherwise wget switches to the dot type.

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

Metaxal
  • 1,083
  • 8
  • 10
  • do you know why it switches to dot type ? some TERM type issue ? force worked for me - thanks! – Goblinhack May 19 '16 at 19:15
  • Use this for showing up progress bar only without target filename with tail value "8". `wget somesite.com/TheFile.jpeg --progress=bar:force 2>&1 | tail -f -n +8` – M.S. Arun Jul 28 '20 at 09:14
13

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.

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

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

ryenus
  • 15,711
  • 5
  • 56
  • 63
4

You can use standard options:

wget --progress=bar http://somesite.com/TheFile.jpeg
MarmiK
  • 5,639
  • 6
  • 40
  • 49
slva
  • 89
  • 1
  • 1
  • 1
    I don't about some other distros, but this is definitely not what OP asked for, at least on Ubuntu. I.e., it still shows other information, but the OP asked for the "progress bar only"... – Dee'Kej May 22 '15 at 10:02
2

This is another example:

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"
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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:

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

This is not literally an answer but this snippet might also be helpful to some coming here for e.g. "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

What was crucial for me is stdbuf(1).

Michael Shigorin
  • 982
  • 10
  • 11
  • 3
    Can you explain what this long line does? If you state already that this is "not literally an answer", how is that line related to the question? – Nico Haase Sep 11 '19 at 11:58
  • This is related through a potential search direction, that's what I've stated; the command line runs wget in "C" locale with arguments to make it output its progress in a way that's suitable for further processing (with I/O buffering turned off) into zenity's progress bar -- resulting in a sort of nice GUI for some download helper, for example. – Michael Shigorin Sep 12 '19 at 17:43
  • 1
    Please add all explanation to the answer itself, not to the comment section – Nico Haase Sep 12 '19 at 19:34
  • Can you [update](https://stackoverflow.com/posts/32721565/edit) your answer? – Peter Mortensen Oct 31 '21 at 16:23