How to display HTTP response code

Use curl utility to verify the HTTP response code for the given URL.

The simplest way to display HTTP response code is to use quiet mode, discard output and display the numerical response code that was found in the last retrieved transfer after executing GET method.

$ curl --silent --output /dev/null --write-out "%{http_code}\n"

The solution mentioned above does not follow redirects, so we need to follow Location: header and a 3XX response code.

$ curl --location --silent --output /dev/null --write-out "%{http_code}\n"

This solution can be upgraded further to fetch only headers instead of the whole document, but you need to be aware that HEAD method can be blocked on the server-side.

$ curl --head --location --silent --output /dev/null --write-out "%{http_code}\n"