如何在使用curl下载时跳过已经存在的文件? [英] How to skip already existing files when downloading with curl?

查看:969
本文介绍了如何在使用curl下载时跳过已经存在的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to curl to download a link, but I want it to skip files that already exist. Right now, the line of code I have will continue to overwrite it no mater what:

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

如何实现?

推荐答案

您可以将 curl 的调用放在内如果 / p>

You could just put your call to curl inside an if block:

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

还要注意,在你的例子中,你有 $ url 在单引号内,这将不会做你想要的。比较:

Also note that in your example, you've got $url inside single quotes, which won't do what you want. Compare:

echo '$HOME'

To:

echo "$HOME"

此外, curl - silent 选项,可以在脚本中使用。

Also, curl has a --silent option that can be useful in scripts.

这篇关于如何在使用curl下载时跳过已经存在的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆