View Only Headers with Curl

When working with curl, it can give lots of excellent and detailed information, but sometimes it is too much! Today I’m fiddling with the caching headers on a client’s application, so I’m only interested in seeing the headers and not the body of the response. Making a HEAD request changes the output I get, so I really do want to GET and then only see the headers.

Handily, when you use the -v verbose flag with curl, it sends the output to stdout as usual, but the extra information including the headers goes to stderr. This means that I can therefore view the headers only throwing away stdout completely:

curl -v -s http://awesome-site.com 1> /dev/null

(you need the -s to stop curl from “helpfully” printing progress bars as well)

9 thoughts on “View Only Headers with Curl

  1. Actually the HEAD request can sometimes be different to a GET – and my trick above works for POST and other verbs as well. So yes, curl -I will take you some distance, but sometimes you need to see the headers of a request you’re actually making, rather than crafting a new one.

  2. This is great! The other “simplified” versions in the comments do not actually work in the same way, as they only print response headers, not require+response headers

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.