5 ms·
For me the killer feature of wget is that by default it downloads a file with a name derived from the url. You do: wget url://to/file.htm and a file name
by enriquto 3y ago
For me the killer feature of wget is that by default it downloads a file with a name derived from the url.
You do:
wget url://to/file.htm
and a file named "file.htm" appears in your cwd.
Using curl, you would have to do
curl url://to/file.htm > file.htm
or some other, less ergonomical, incantation.
- dwb 3y agocurl -O https://curl.se/docs/manpage.html#-O https://curl.se/docs/manpage.html#-O
- OskarS 3y agoI much prefer the fact that curl doesn't do this by default (but has the option), it much closer matches the behavior of most unix-y tools. Makes it so much easier to put it into pipelines.
- throw0101a 3y agoWhat's "better" depends on whether you 'just' want to download a file, or if you want to build an larger workflow. For me, I usually want to download files and I'm usually not doing any more processing, so I tend to type in *wget" first.
- TheFuzzball 3y agoI usually use `curl -OL <url>` or `curl -L -o <local-filename> <url> instead of wget. wget is better for download lists, but I'd accept the argument that a simple shell script is similarly easy.
- mananaysiempre 3y agoAlso -OJ : with -O you get the name derived from the URL (the initial one, I think, even if redirects are being followed), with -OJ you get the one from the Content-Disposition header or the final URL, the way browsers do it. Of course, plain -O is safer. (For parity with Wget, you might also want to add -R to set the downloaded file’s mtime according to the Last-Modified header.)
- darnir 3y agoWget will give you an equivalent with the --content-dispisition flag. I would like for it to be the default, but it would likely break backwards compatibility with some scripts that except a different output filename.
- madfucker69 3y ago-OJ is nice but doesn't work with -C- for some reason
- mananaysiempre 3y agoTrue. AFAIU the reason is that Curl wants to make a single request (modulo redirects), whereas making -OJC- work would require two: issue a HEAD to receive the Content-Disposition header and learn the file name, then look at that file and see how long it is, then issue a GET with a Range header to request the suffix you still need to download. With other methods I don’t think you could make this work at all. I don’t know if Stenberg is opposed to a GET-specific solution, perhaps that could be a fun project. (Although I’ve encountered noncompilant servers that couldn’t handle HEADs.)
- throw0101a 3y ago> curl -O Yes. But the GP said by default.
- dwb 3y agoI was obviously responding to the curl command they posted. I didn't say anything about default behaviour.
- malablaster 3y agoNo, OP said… > you would have to do `curl url://to/file.htm > file.htm` or some other, less ergonomical, incantation … which begs the conclusion that OP is unaware of `-O`.
- enriquto 3y agoI'm well aware of curl's -O (long form: --remote-name), but it has an unfortunate clash with an option of the same name from wget (long form: --output-document). These options have closely related yet very different meanings. Using these options without looking at the manpage fills me with a sense of dread that I prefer to avoid.
- photochemsyn 3y agoman 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'
- deleted 3y ago[deleted]
- johnchristopher 3y agoYeah, but: wget "url://to/file.htm?uid=foo&q=bar&rnd=4"
- scatters 3y ago`&unused=.htm`. It usually works.
- jraph 3y agoAt this point you might as well use the -o option (-o file.htm). It's easier and easier to understand. I'd prefer wget to be a bit more clever when handling URLs query strings though, but I guess changing this behavior now might break some scripts.
- em-bee 3y agowell, depends on the usecase. sometimes you want the whole url, like when i want to mirror a site and it has stuff like foo.html?page=1 foo.html?page=2 ... wget does have options to use the name proposed by the server, and so another option to remove the query arguments would be useful, and in line with those.
- darnir 3y agoA new option to strip query parameters from the output filename would be interesting. But its not so simple. When combined with recursion, one will often see a lot of pages with the same name but different query parameters. How should they be stored on disk? There's a couple of different issues I can think of. However, if the potential issues can be resolved with sane defaults, I think this would be a great new switch to add.
- em-bee 3y agoyes, exactly. i think that the option would have to be ignored when doing recursion. or alternatively use the .1 .2 ... method like with all cases where a file of that name already exists.
- inopinatus 3y agoI’ve always seen this as a misfeature of wget, on the general principle that command-line utilities should write their principal result to stdout unless otherwise instructed.
- deleted 3y ago[deleted]
- Annatar 3y ago[dead]
- grayhatter 3y agoor curl -O which is more ergonomic that "killer feature" for cat would be turn `cat file.html` into `cat file.html > file.html` which means if you actually wanted to cat instead of cp you'd also need `cat file.html -o -` kinda glad curl doesn't have that killer feature.