wget - 保留同名文件

wget - keep the files with same name

我正在使用 wget 从数据库下载一些文件,但数据库中的一些文件同名。因此,当我下载 2 个同名文件时,文件会中断。我想知道是否有办法保留这两个文件。例如,我下载了名为 a.png 的文件,然后我下载了另一个同名的不同文件,并将名称更改为 2.png
简单地说,我只需要一些能够识别同名文件并为第 2、第 3、第 4 赋予不同名称的东西,...

谢谢..

使用 wget -nd 选项确保它破坏现有文件。

根据man wget

-nd
--no-directories
  Do not create a hierarchy of directories when retrieving recursively.  With this 
  option turned on, all files will get saved to the current directory, without 
  clobbering (if a name shows up more than once, **the filenames will get
  extensions .n**).

另外我想补充一点:

When running Wget without -N, -nc, -r, or -p, downloading the same file in the same directory will result in the original copy of file being preserved and the second copy being named file.1. If that file is downloaded yet again, the third copy will be named file.2, and so on. (This is also the behavior with -nd, even if -r or -p are in effect.) When -nc is specified, this behavior is suppressed, and Wget will refuse to download newer copies of file.

我想用“-O”是没办法的。所以,我把它留在那里并修改了程序。我在下载之前检查了文件名是否存在。如果退出,我会像这样下载文件 "name$i.png"。而且,我将存在的文件名写入 .txt 文件。所以,稍后我会手动更改它们。