Can anyone explain me the below curl command and how it works :

STATUS_CODE=`curl –output /dev/null –silent –head –write-out ‘%{http_code}\n’ $next`
# If you want to set a timeout then add –max-time 15, here 15 is 15seconds

You seem to be missing a few double dashes, probably the result of copy and paste:

STATUS_CODE=`curl --output /dev/null --silent --head --write-out ‘%{http_code}\n’ $next`

Assuming that you call this with next being a url (e.g. in a loop or reading from a file):

  • --output /dev/null discards the normal output
  • --silent suppresses the progress meter
  • --head fetch header only
  • --write-out '%{http_code}\n' prints the status code

So in the end the status of the URL request ends up in STATUS_CODE

(And if you want to set the timeout, then use double dashes too: --max-time).

| improve this answer | |
  • Hi Anthon, I have tried the same command but it's returning the error code as "302". what does it mean ?? Also does the curl command work in the same manner for https as it work for http. – user2523599 Jul 2 '13 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.