Print Only HTTP Status Code With Curl

When handling HTTP requests, it is often necessary to check the status code of a response quickly, without retrieving the full headers or body. This is useful for testing API endpoint availability or monitoring website health. This tutorial shows how to display only the HTTP status code using cURL. You can achieve this using cURL’s -w (write-out) option and its built-in http_code variable, which outputs custom information to the standard output after the request is complete.

Windows

curl -w "%{http_code}" -o NUL -s https://httpbin.org/get

Linux

curl -w "%{http_code}" -o /dev/null -s https://httpbin.org/get

The -o option is used to discard the response output, as we are only interested in the HTTP status code. The -s option makes Curl silent, suppressing progress details and additional information.

The command will return HTTP status code such as 200.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.