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

-
Have Questions? Post them here!
More Posts related to cURL,
- cURL Example using IP (IPv4 and IPv6) address and Port
- Efficient way to perform HTTP cURL GET/POST Requests with Payload
- Save cURL Command Output to a external file
- How to set Connection and Max Timeout for cURL Request with Examples
- [fix] command not found curl
- Fetch only content-type using cURL Command
- Trace using cURL Command Example
- Hide cURL Outputs and Errors on Terminal
- cURL Option to show HTTP Response Status Code
- Downloading Google Chrome using cURL Command
- Perform Basic Authentication using cURL with Examples
- List of 28 Protocols supported by cURL with Examples
- URL Encode cURL HTTP GET\POST Data with Examples
- Get the Size of HTTP Response using cURL Command (Content Length)
- How to get cURL Command to run in verbose mode?
- Get cURL command from Chrome Inspect Network HTTP URL
More Posts:
- Types of brackets used in Programming Languages - Codes - 2022
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException - Android
- How to check zsh installed version using terminal - MacOS
- How to do a Reverse Image Search Using Google Tools - Google
- How to make a Android button act as a toggle button - Android
- Fix for zsh: command not found: brew - zsh
- [fix] zsh: illegal hardware instruction python TensorFlow M1/M2 Mac - zsh
- Keyboard shortcut to close tab in Notepad++ - NotepadPlusPlus