Live data from Hacker News

The curl-wget Venn diagram

daniel.haxx.se

111–120 of 159 posts

Re: The curl-wget Venn diagram

#111

On the cURL side; ridiculous manual I regularly forget the order for the values for --resolve , try searching for that word and figuring it out quickly I've been relegated to grepping a flippin' manual

A trick I've found useful when searching large man pages for a flag --foo is to search for `␣␣--foo` (note the two leading spaces). In my experience this always hits the line where the flag is defined instead of irrelevant mentions of that flag, and it's faster than paging through the manual by hand.

Ah, good call - I've tried a variation of that with one space and been left disappointed; two works a treat!

Re: The curl-wget Venn diagram

#112
post #62

I would also add at least "sane default options", "continues downloads" and "retries on error" to the Wget column. I recently had to write a script that downloads a very large file over a somewhat unreliable connection. The common wisdom among the engineers is that you need to use Wget for this job. I tried using curl but out of the box it could not resume or retry the download. I would have to study the manual and s…

Also add -i which lets wget read URLs from a file. In particular wget -i - which makes it read from standard input, and is very useful in pipelines. curl cannot, AFAIK, do this. People usually suggest using xargs, which is a mediocre substitute because it waits for all the URLs to arrive before invoking curl, giving up any chance at parallelism between the command generating the URLs and the one downloading them.

xargs doesn't have to wait, you can specify the number of items to include in a single sub-command and it'll batch things as they come in. For instance:

    ds@swann3:~# (for x in {1..100}; do sleep 0.1s; echo $x >&2; echo $x; done) | xargs -L5 echo
    1
    2
    3
    4
    5
    1 2 3 4 5
    6
    7
    8
    9
    10
    6 7 8 9 10
    11
    12
    [... and so on ...]
If the xargs call uses -I then --max-lines=1 is implied anyway.

If you replace echo with something that sleeps you'll see that the pipe doesn't stall waiting on xargs so the process producing the list can keep pushing new items to it as they are found:

    ds@swann3:~# (for x in {1..100}; do sleep 0.1s; echo $x >&2; echo $x; done) | xargs --max-lines=5 ./echosleepecho
    1
    2
    3
    4
    5
    starting 1 2 3 4 5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    done 1 2 3 4 5
    starting 6 7 8 9 10
    15
    16
    17
    18
    19
    [... and so on until ...]
    98
    99
    100
    done 46 47 48 49 50
    sleeping for 51 52 53 54 55
    done 51 52 53 54 55
    sleeping for 56 57 58 59 60
    [... and so on until xarg's stdin is exhausted]

And you can stop the calls made by xargs being sequential too for more parallelism with the --max-procs option (or use parallel instead of xargs):

    ds@swann3:~# (for x in {1..100}; do sleep 0.1s; echo $x >&2; echo $x; done) | xargs --max-lines=3 --max-procs=10 ./echosleepecho
    1
    2
    3
    sleeping for 1 2 3
    4
    5
    6
    sleeping for 4 5 6
    7
    8
    9
    sleeping for 7 8 9
    10
    11
    12
    sleeping for 10 11 12
    done 1 2 3
    13
    14
    15
    sleeping for 13 14 15
    done 4 5 6
    16
    [... and so on ...]
(I adjusted max-lines in that last example because my current timings made things line up in a manner that made the effect less obvious, adjusting the timings would have been equally valid, in a less artificial example like calling curl to get many resources timings will of course be less regular, perhaps these examples can be improved by randomising the sleeps)

I'm not sure what you would do about error handling in all this though, more experimentation necessary there before I'd ever do this in production!

Re: The curl-wget Venn diagram

#113

I would also add at least "sane default options", "continues downloads" and "retries on error" to the Wget column. I recently had to write a script that downloads a very large file over a somewhat unreliable connection. The common wisdom among the engineers is that you need to use Wget for this job. I tried using curl but out of the box it could not resume or retry the download. I would have to study the manual and s…

Retry with `wget` was one of the most incredible Linux distro included features when I started running it at home. Pretty crucial thing on 56K dialup, and it worked better than the Windows tools I was aware of at the time.

Our dialup used to disconnect every 2 hours by design. wget and wvdial were the only alternative to mail-ordering CDs

Re: The curl-wget Venn diagram

#114
post #86

Earlier quoted context omitted.

You recall incorrectly. curl's -C flag does not work as-is. You must specify the offset from where it should continue. Why doesn't it take the resumed file's existing length as the guess by default? What else could the user want outside of some very exotic cases? Yes, I want retries. They should be the default for a user-facing tool. Try searching the curl's manual page for "retry". There are no less than 5 different…

What is a sane default for retries? is it to loop indefinitely? should it retry against the same TCP connection or establish a new one? To the same IP it picked the first time or a different one, or reresolve the DNS entirely? against the same resolver? IMO theres too much complexity for 'sane defaults' to not just be 'surprising behavior' for someone else's use case.

It's indeed miraculous how Wget got this right

Re: The curl-wget Venn diagram

#115
post #10

Earlier quoted context omitted.

curl -O https://curl.se/docs/manpage.html#-O

> curl -O Yes. But the GP said by default .

man curl | grep -C 2 " -O"

--remote-name-all This option changes the default action for all given URLs to be dealt with as if -O, were used for each one. So if you want to disable that for a specific URL after --remote-name-all has been used, you must use "-o -" or --no-remote-name.

alias curl='curl --remote-name-all'

Re: The curl-wget Venn diagram

#116

I would also add at least "sane default options", "continues downloads" and "retries on error" to the Wget column. I recently had to write a script that downloads a very large file over a somewhat unreliable connection. The common wisdom among the engineers is that you need to use Wget for this job. I tried using curl but out of the box it could not resume or retry the download. I would have to study the manual and s…

I agree on the "sane defaults". Just the fact that `wget url` downloads a URL and saves it makes it a winner for me in command-line use.

Well, the point of the article is that they are not cpmpetitors and are used differently. For me, 99% of the time i'm curl-ing some API and I definitely don't want to save the result to disk (but often want to pipe it to grep/jq).

Re: The curl-wget Venn diagram

#117
post #104

Earlier quoted context omitted.

No, `-C -` is not a flag. It is specifying the `-C` argument with obscure special value of `-`, which causes curl to determine the offset to continue from the output file length. This might be obvious to you if you are well-versed in curl command line, but it's by no means expected or obvious like a simple flag. > But curl is perfectly capable of resuming downloads automatically, you're just (very arrogantly) wrong o…

> I've never claimed it doesn't. Yes you did: > You must specify the offset from where it should continue No, you mustn't, you can specify - and it does exactly what you want. The docs are very clear and even provide examples. At some point you should stop blaming curl for your inability to read a man page and admit that you were simply mistaken.

[deleted]

Re: The curl-wget Venn diagram

#118
post #104

Earlier quoted context omitted.

No, `-C -` is not a flag. It is specifying the `-C` argument with obscure special value of `-`, which causes curl to determine the offset to continue from the output file length. This might be obvious to you if you are well-versed in curl command line, but it's by no means expected or obvious like a simple flag. > But curl is perfectly capable of resuming downloads automatically, you're just (very arrogantly) wrong o…

> I've never claimed it doesn't. Yes you did: > You must specify the offset from where it should continue No, you mustn't, you can specify - and it does exactly what you want. The docs are very clear and even provide examples. At some point you should stop blaming curl for your inability to read a man page and admit that you were simply mistaken.

You still fail to understand that curl's -C does not behave as a simple flag but as an switch with a mandatory argument. And there's a magic special value for that argument that finally enables the expected behavior. It's unintuitive, hard to remember and not in agreement with usability. While I agree that curl is powerful I will not concede that it's CLI is user friendly.

Re: The curl-wget Venn diagram

#119

I would also add at least "sane default options", "continues downloads" and "retries on error" to the Wget column. I recently had to write a script that downloads a very large file over a somewhat unreliable connection. The common wisdom among the engineers is that you need to use Wget for this job. I tried using curl but out of the box it could not resume or retry the download. I would have to study the manual and s…

I mean, it all depends on who you are and what you are primarily doing. “Sane defaults” for one person could be everything another doesn’t want.

Re: The curl-wget Venn diagram

#120

I would also add at least "sane default options", "continues downloads" and "retries on error" to the Wget column. I recently had to write a script that downloads a very large file over a somewhat unreliable connection. The common wisdom among the engineers is that you need to use Wget for this job. I tried using curl but out of the box it could not resume or retry the download. I would have to study the manual and s…

curl is an excellently powerful library and utility but I agree that wget has better defaults. I am almost certain to get the behavior that I want by just throwing a URL at wget, including retrying from the point where it had an issue. I actually ran into a case where our corporate firewall was a little too eager to block a download being performed by the Visual Studio installer because of a signature match partway through a specific download. All I had to do to grab the file was have wget download it. No magic incantations, it was just smart enough to not start the download from the beginning after being cut off, and since it started midway it no longer tripped the signature match rule.
Post reply on HN