是的,这是
-c
选项。
--continue
Continue getting a partially-downloaded file. This is useful when you want to
finish up a download started by a previous instance of Wget, or by another
program.
如果文件相同,第二次下载尝试将停止。
$ wget -c https://cdn.sstatic.net/askubuntu/img/logo.png
...
Saving to: ‘logo.png’
...
$ wget -c https://cdn.sstatic.net/askubuntu/img/logo.png
...
The file is already fully retrieved; nothing to do.
注意事项(来自jofel的评论)
如果服务器上的文件发生了变化,-c
选项可能会给出错误的结果。
使用-c
,wget只是简单地向服务器请求已下载文件之外的任何数据,仅此而已。它不会检查已下载文件部分是否有任何更改。因此,你可能会得到一个混合了旧文件和新文件的损坏文件。
本地测试
您可以通过以下方式运行简单的本地Web服务器进行测试(感谢@roadmr的答案):
打开一个终端窗口并输入:
cd /path/to/parent-download-dir/
python -m SimpleHTTPServer
现在打开另一个终端并执行以下操作:
wget -c http://localhost:8000/filename-to-download
请注意,
filename-to-download
是位于
/path/to/parent-download-dir/
目录中的文件,我们希望下载它。
现在,如果您多次运行wget命令,您将会看到:
The file is already fully retrieved; nothing to do.
好的,现在进入`/path/to/parent-download-dir/`目录,并向源文件中添加一些内容。例如,如果它是一个文本文件,在其中添加一行简单的额外内容并保存文件。然后使用`wget -c ...`进行尝试。很好,现在你会看到文件重新下载,但你之前已经下载过它了。
原因:为什么会重新下载?
因为文件的大小变得比之前下载的文件更大,除此之外没有其他原因。
rm example.1
,但是已经接受的解决方案也很好。 - PJ Brunet