Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force wget to overwrite an existing file ignoring timestamp?

Tags:

wget

I tried '-N' and '--no-clobber' but the only result that I get is to retrieve a new copy of the existing example.exe with number a number added using this synax 'example.exe.1'. This is not what I'd like to get. I just need to download and overwrite the file example.exe in the same folder where I already saved a copy of example.com without that wget verifies if the mine is older or newer respect the on example.exe file already present in my download folder. Do you think is i possible or I need to create a script that delete the example.exe file or maybe something that change his modification date etc?

like image 983
Andrew Nexintong Avatar asked May 23 '15 22:05

Andrew Nexintong


2 Answers

If you specify the output file using the -O option it will overwrite any existing file.

For example:

wget -O index.html bbc.co.uk

Run multiple times will keep over-writting index.html.

like image 53
PeterSW Avatar answered Nov 01 '22 03:11

PeterSW


wget doesn't let you overwrite an existing file unless you explicitly name the output file on the command line with option -O.

I'm a bit lazy and I don't want to type the output file name on the command line when it is already known from the downloaded file. Therefore, I use curl like this:

curl -O http://ftp.vim.org/vim/runtime/spell/fr.utf-8.spl

Be careful when downloading files like this from unsafe sites. The above command will write a file named as the connected web site wishes to name it (inside the current directory though). The final name may be hidden through redirections and php scripts or be obfuscated in the URL. You might end up overwriting a file you don't want to overwrite.

And if you ever find a file named ls or any other enticing name in the current directory after using curl that way, refrain from executing the downloaded file. It may be a trojan downloaded from a rogue or corrupted web site!

like image 45
Frédéric Marchal Avatar answered Nov 01 '22 05:11

Frédéric Marchal