curlcommand-linedownload

How to skip already existing files when downloading with 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 &

How this can be achieved?


Solution

  • 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.