Using --fail will make the exit status nonzero if the request fails. Using --head will avoid loading the contents of the file because it is not needed for this check. Using --silent avoids the state or errors when emitting the check itself.
if curl --output /dev/null --silent --head --fail "$url"; then echo "URL exists: $url" else echo "URL does not exist: $url" fi
If your server refuses HEAD requests, an alternative is to request only the first byte of the file:
if curl --output /dev/null --silent --fail -r 0-0 "$url"; then
Charles Duffy Aug 30 2018-12-12T00: 00Z
source share