In order to know the HTTP(S) Response status code using cURL command, make use of the -I option to display the response headers.
Example:% $ curl -I https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
cross-origin-opener-policy-report-only: same-origin-allow-popups; report-to="gws"
date: Mon, 12 Dec 2022 09:38:06 GMT
expires: Wed, 11 Jan 2023 09:38:06 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
If you just want to display the HTTP response status code, make use of the -s option and pipe it with awk 'NR==1' to just display the 1st line.
% curl -Is https://google.com | awk 'NR==1'
HTTP/2 301
% curl -Is https://code2care.org | awk 'NR==1'
HTTP/2 200
curl -Is https://google.com/code2care | awk 'NR==1'
HTTP/2 404

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to cURL,
- Hide cURL Outputs and Errors on Terminal
- cURL DELETE Request with Examples
- Downloading Google Chrome using cURL Command
- List of 28 Protocols supported by cURL with Examples
- Get the Size of HTTP Response using cURL Command (Content Length)
- How to convert a Postman request to cURL Command
- How to URL Encode Data for a cURL Request Parameters
- Get cURL command from Chrome Inspect Network HTTP URL
- Fetch only content-type using cURL Command
- cURL -d Option with Examples
- cURL Option to show HTTP Response Status Code
- URL Encode cURL HTTP GET\POST Data with Examples
- How to get cURL Command to run in verbose mode?
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer
- [fix] command not found curl
- How to Pretty Print cURL JSON Output in Terminal
- Capture cURL Request Output to a File
- List of common cURL Error Codes
- How to pass authorization header using cURL
- Perform Basic Authentication using cURL with Examples
- Trace using cURL Command Example
- Efficient way to perform HTTP cURL GET/POST Requests with Payload
- Save cURL Command Output to a external file
- cURL Example using IP (IPv4 and IPv6) address and Port
- How to follow redirects in cURL Command Request
More Posts:
- Best way to Convert Primitive long to int in Java with some Cautions - Java
- Android Disable EditText from Auto Focus on Activity load - Android
- How to force quit or kill Notepad++ Process - NotepadPlusPlus
- How to show Videos on SharePoint Page - SharePoint
- [fix] docker exec requires at least 2 arguments - Docker
- How to check of Updates on Microsoft Edge Browser on Mac (macOS) - MacOS
- Java JDBC NumberFormatException: For input string - Java
- Change Home Page on Safari for Mac (macOS) - MacOS