How to skip already existing files when downloading with curl?
You could just put your call to curl
inside an if
block:
if ! [ -f /home/$outputfile ]; then curl -o /home/$outputfile "url"fi
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"
Also, curl
has a --silent
option that can be useful in scripts.
You can use curl option -C -
. This option is used to resume a broken download, but will skip the download if the file is already complete. Note that the argument to -C
is a single dash. A disadvantage might be that curl still briefly contacts the remote server to ask for the file size.
Use wget with --no-clobber
instead:
-nc
,--no-clobber
: skip downloads that would download to existing files.
Example:
wget -nc -q -O "/home/$outputfile" "$url"