Tagged as: curl linux

Curl can not only return the body of a HTTP request, but also the response headers.

The curl option needed for this is -i, which makes curl include the headers along with the output.

For example:

curl -i "http://example.com"

returns this content:

HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Sun, 06 Mar 2016 16:03:36 GMT
Etag: "359670651+gzip"
Expires: Sun, 13 Mar 2016 16:03:36 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (ewr/15BD)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

<!doctype html>
<html>
<head>
<title>Example Domain</title>
...

If you only want the headers, and not the rest of the content, you can use this command instead:

curl -s -D - "http://example.com" -o /dev/null

This redirects the headers to the standard output and the rest of the output to /dev/null.