如何使用卷曲下载时跳过已存在的文件?(How to skip already existing fi

2019-07-30 21:00发布

我想curl下载链接,但我想它跳过已经存在的文件。 现在,我的代码行会继续覆盖它没有什么母校:

curl '$url' -o /home/$outputfile &>/dev/null &

这可怎么实现的?

Answer 1:

你可以只是把你的电话到curl的内侧if块:

if ! [ -f /home/$outputfile ]; then
  curl -o /home/$outputfile "url"
fi

另外请注意,在你的榜样,你有$url单引号,你想要什么,不会做里面。 相比:

echo '$HOME'

至:

echo "$HOME"

此外, curl具有--silent选项,可以在脚本中非常有用。



Answer 2:

使用wget与--no-clobber来代替:

-nc--no-clobber :跳过下载将下载到现有文件。

例:

wget -nc -q -O "/home/$outputfile" "$url" 


Answer 3:

您可以使用卷曲选项-C - 此选项是用来恢复被中断下载,但会跳过下载该文件是否已经完成。 需要注意的是参数-C是一个破折号。 缺点可能是卷曲还是短暂接触远程服务器要求的文件大小。



Answer 4:

curl可以支持跳过的文件,当您与使用-O-J ,但其行为是不一致的。

-J--remote-header-name )基本上告诉-O--remote-name使用服务器指定)选项Content-Disposition ,而不是提取的URL文件名文件名。 在这样的curl并不真正知道服务器会返回一个文件名,所以可以忽略安全措施的现有文件。

来源: 回复:-J“拒绝覆盖......”

例如:

$ curl -LJO -H 'Accept: application/octet-stream' 'https://api.github.com/repos/x/y/releases/assets/12345
Warning: Refusing to overwrite my_file.bin: File 
Warning: exists
curl: (23) Failed writing body (0 != 16384)

然而,由于已经提到的,其行为是不可预测的,它不适合所有文件。



文章来源: How to skip already existing files when downloading with curl?