When I download file using wget it copies create time from original file on server by default:

> wget https://pbs.twimg.com/media/ByEt7bVIQAAzDVq.jpg
> ls -l  ByEt7bVIQAAzDVq.jpg
-rw------- 1 d9k d9k 20K Sep 21  2014 ByEt7bVIQAAzDVq.jpg

How automatically overwrite dowloaded file time to current without using touch after each download?


As man wget explains:

           Don't set the local file's timestamp by the one on the server.

           By default, when a file is downloaded, its timestamps are set to
           match those from the remote file. This allows the use of
           --timestamping on subsequent invocations of wget. However, it is
           sometimes useful to base the local file's timestamp on when it was
           actually downloaded; for that purpose, the
           --no-use-server-timestamps option has been provided.

That is, to make the timestamp on the downloaded file represent when it was created on the local machine, use the --no-use-server-timestamps flag:

ek@Io:~$ wget https://pbs.twimg.com/media/ByEt7bVIQAAzDVq.jpg --no-use-server-timestamps
--2015-04-05 00:04:55--  https://pbs.twimg.com/media/ByEt7bVIQAAzDVq.jpg
Resolving pbs.twimg.com (pbs.twimg.com)...
Connecting to pbs.twimg.com (pbs.twimg.com)||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19846 (19K) [image/jpeg]
Saving to: ‘ByEt7bVIQAAzDVq.jpg’

ByEt7bVIQAAzDVq.jpg 100%[=====================>]  19.38K  --.-KB/s   in 0.04s  

2015-04-05 00:04:56 (538 KB/s) - ‘ByEt7bVIQAAzDVq.jpg’ saved [19846/19846]

ek@Io:~$ ls -l ByEt7bVIQAAzDVq.jpg 
-rw-rw-r-- 1 ek ek 19846 Apr  5 00:04 ByEt7bVIQAAzDVq.jpg

The advantage of the default behavior, as explained in the manpage, is in case you later want to retrieve the file again, automatically downloading it only if a newer one is available.

| improve this answer | |

Found it:

% wget --no-use-server-timestamps https://pbs.twimg.com/media/ByEt7bVIQAAzDVq.jpg
% ls -l  ByEt7bVIQAAzDVq.jpg
-rw------- 1 d9k d9k 19846 Apr  5 07:02 ByEt7bVIQAAzDVq.jpg
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.