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
![cURL get Content-Type cURL get Content-Type](https://code2care.org/q/fetch-only-content-type-using-curl-command/images/cURL get Content-Type.jpg)
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:
- Enable Native Dark Mode in Notepad++ - NotepadPlusPlus
- Fix: Teams is in preview in Safari on Mac - Teams
- How to remove/delete a directory in Linux/macOs - Linux
- List of Java JDBC Database Driver Jars, Classes and URLs Details - Java
- SharePoint Designer Workflow error - Coercion Failed: Input cannot be null for this coercion - SharePoint
- Open VS Code Command Palette using Keyboard Shortcut - Shortcuts
- How to make a dummy phone call from Android Emulator device - Android
- [Fix] Docker Error response from daemon: manifest for :latest not found: manifest unknown - Docker