Mac OS X or Linux | get http headers of an url from the terminal using curl

Written by
Date: 2012-05-27 09:18:00 00:00


When you are a sysadmin or web developer, you need to know the http headers your app or webpage is sending to the browser.

Doing that with browser using Chrome or Firefox plugins is easy. Anyway I always prefer to use the command terminal, no matter if I'm working on my Linux or Mac OS X powered laptop. As curl is usually available by default in all Linux distributions, at least all I have test, and it is available in my Macbook Pro too, let's use curl

The command to check http headers from Linux or Mac terminal is:

curl -I url

Let's see an example:

curl -I http://www.google.com/

The http headers for google are:

HTTP/1.1 200 OK
Date: Sun, 27 May 2012 13:24:32 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=e3fa4b2d079931fa:FF=0:TM=1338125072:LM=1338125072:S=G8ydds2Q--intpj9; expires=Tue, 27-May-2014 13:24:32 GMT; path=/; domain=.google.com
Set-Cookie: NID=60=iqgo_jgJmL9adf52lbd2T50HJw6Yuw-YotHC897obdvOk5uVvIithMIoDvc4VyUlurGXxc0nM2cSg70wCJmRgit1DQt9CqmYoBK8KfLY-u9E1YeNvFpe1XEekok4iXFzM; expires=Mon, 26-Nov-2012 13:24:32 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked