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
Share:
186,582
Gnanam
Author by

Gnanam

Updated on September 17, 2022

Comments

  • Gnanam
    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 this file1.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.

    1. -nc => --no-clobber
    2. -N => Turn on time-stamping
    3. -r => Turn on recursive retrieving
  • Gnanam
    Gnanam almost 14 years
    There is no direct option in wget command that does this without me specifying explicitly using -O filename?
  • aleroot
    aleroot almost 14 years
    It 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
    Gnanam almost 14 years
    I'm not a Linux expert. What is the basic difference between wget and curl? I'm sure that each command is meant for some specific purpose.
  • Mike Broughton
    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
    Gnanam almost 14 years
    Those 2 links are really helpful to understand the difference.
  • sth
    sth over 10 years
    That 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.