How to allow wget to overwrite files
186,582
Solution 1
wget -q http://www.whatever.com/filename.txt -O /path/filename.txt
-q is quiet mode so you can throw it in a cron without any output from the command
Solution 2
This option works
wget -N http://server/folder/file1.html
info
-N, --timestamping don't re-retrieve files unless newer than
local.
Solution 3
Use curl
instead?
curl http://server/folder/file1.html > file1.html
Author by
Gnanam
Updated on September 17, 2022Comments
-
Gnanam over 1 year
Using
wget
command, how do I allow/instruct to overwrite my local file everytime, irrespective of how many times I invoke.Let's say, I want to download a file from the location: http://server/folder/file1.html
Here, whenever I say
wget http://server/folder/file1.html
, I want thisfile1.html
to be overwritten in my local system irrespective of the time it is changed, already downloaded, etc. My intention/use case here is that when I call wget, I'm very sure that I want to replace/overwrite the existing file.I've tried out the following options, but each option is intended/meant for some other purpose.
- -nc => --no-clobber
- -N => Turn on time-stamping
- -r => Turn on recursive retrieving
-
Gnanam almost 14 yearsThere is no direct option in
wget
command that does this without me specifying explicitly using-O filename
? -
aleroot almost 14 yearsIt seems that there is no way to force overwriting every files when downloading files using wget. However, use -N option can surely force downloading and overwriting newer files. wget -N Will overwrite original file if the size or timestamp change
-
Gnanam almost 14 yearsI'm not a Linux expert. What is the basic difference between
wget
andcurl
? I'm sure that each command is meant for some specific purpose. -
Mike Broughton almost 14 years@Gnanam: They overlap a lot in basic CLI utility, actually. Both can make an HTTP connection and save the result to disk. For a run down on the differences check out daniel.haxx.se/docs/curl-vs-wget.html Regardless, the above usage is complete valid. There are other tools in this general area, too: curl.haxx.se/docs/comparison-table.html
-
Gnanam almost 14 yearsThose 2 links are really helpful to understand the difference.
-
sth over 10 yearsThat
wget
line doesn't really do the correct thing because it creates a hierarchy of of subdirectories.curl -O
on the other hand correctly downloads the file, overwriting existing copies.