Using curl -I to detect the MIME type of a URL

curl is a command line tool for transferring files with URL syntax.

The -I option retrieves just the header information


$ curl -I
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Date: Tue, 25 Aug 2009 00:24:38 GMT
Expires: Thu, 24 Sep 2009 00:24:38 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219

and lots of other interesting tidbits too:

curl -I
HTTP/1.1 200 OK
Date: Tue, 25 Aug 2009 00:26:12 GMT
Content-Type: image/jpeg
Connection: keep-alive
Server: Apache/2.0.52 (Red Hat)
Cache-Control: max-age=315360000
Expires: Mon, 28 Jul 2014 23:30:00 GMT
Last-Modified: Mon, 17 Aug 2009 10:10:16 GMT
Accept-Ranges: bytes
Content-Length: 124866
Age: 12
X-Cache: HIT from
X-Cache-Lookup: HIT from
Via: 1.1 (squid/2.7.STABLE6)