If you only want to fetch the content-type for a response, make use of the --write-out option and the variable content_type
Example:% curl -s -o /dev/null -w "%{content_type}\n" http://example.org
Output:
text/html; charset=UTF-8
You may also make use of the -I option along with grep,
% curl -I http://example.org
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Age: 584814
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 12 Dec 2022 11:33:10 GMT
Etag: "3147526947"
Expires: Mon, 19 Dec 2022 11:33:10 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dcb/7F60)
X-Cache: HIT
Content-Length: 648
Example:
% curl -Is http://example.org | grep -iF 'Content-Type'
Output:
Content-Type: text/html; charset=UTF-8
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:
- [Fix] Microsoft Teams Error code - 2:-1012 - Teams
- Android is starting optimizing... app 1 of 1 - Android
- Test internet speed using macOS Terminal command - MacOS
- How to Open TextEdit on Mac - MacOS
- How to generate client id and secret to register SharePoint App with OAuth - SharePoint
- [fix] Loading class com.mysql.jdbc.Driver is deprecated - MySQL
- cURL DELETE Request with Examples - cURL
- Fix: 403 Forbidden/Access Denied Error during Windows Software Updates - Windows