当我使用 wget 下载文件时,它默认从服务器上的原始文件复制创建时间:
> wget https://pbs.twimg.com/media/ByEt7bVIQAAzDVq.jpg
> ls -l ByEt7bVIQAAzDVq.jpg
-rw------- 1 d9k d9k 20K Sep 21 2014 ByEt7bVIQAAzDVq.jpg
如何touch
在每次下载后不使用的情况下自动将下载的文件时间覆盖为当前时间?
答案1
作为man wget
解释:
--no-use-server-timestamps
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.
也就是说,为了使下载文件上的时间戳代表它在本地机器上的创建时间,请使用以下标志--no-use-server-timestamps
:
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)... 199.96.57.7
Connecting to pbs.twimg.com (pbs.twimg.com)|199.96.57.7|: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
正如手册页中所述,默认行为的优点是,如果您以后想要再次检索该文件,则仅在有较新的文件可用时才自动下载该文件。
答案2
找到了:
% 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