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!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to cURL,
- cURL Option to show HTTP Response Status Code
- URL Encode cURL HTTP GET\POST Data with Examples
- Capture cURL Request Output to a File
- Fix: Curl No Match Found Error
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer
- Send JSON Data as Payload using cURL HTTP POST Request
- cURL: Show Request and Response Headers
- Get cURL command from Chrome Inspect Network HTTP URL
- Save cURL Command Output to a external file
- cURL DELETE Request with Examples
- How to URL Encode Data for a cURL Request Parameters
- cURL Example using IP (IPv4 and IPv6) address and Port
- How to convert a Postman request to cURL Command
- [fix] command not found curl
- How to Pretty Print cURL JSON Output in Terminal
- How to follow redirects in cURL Command Request
- How to pass authorization header using cURL
- cURL -x Use of HTTP Proxy Server Examples
- Downloading Google Chrome using cURL Command
- How to get cURL Command to run in verbose mode?
- List of 28 Protocols supported by cURL with Examples
- Hide cURL Outputs and Errors on Terminal
- cURL -d Option with Examples
- How to show SSL Certificate details using cURL Command
- Perform Basic Authentication using cURL with Examples
More Posts:
- 33: Python Program to find the current time in India (IST) - Python-Programs
- How to connect Relational and NoSQL databases with Spring Boot - HowTos
- Check If Python pip modules are outdated and New Version is Available - PIP
- Remove Now Playing icon from macOS Big Sur Menu Bar - MacOS
- Android Parsing Data for android-L failed Unsupported major.minor version 51.0 Error - Android
- How to Rename a file using Mac Terminal - MacOS
- Fix SharePoint Error - Unable to Display Named Item - SharePoint
- Read a file using Java 8 Stream - Java