By Alvin Alexander. Last updated: April 8, 2018
Curl FAQ: How do I use curl to get the headers from a website URL?
Short answer: Use curl's -I
option, like this:
$ curl -I URL
Here's a specific example, including a real URL and results:
$ curl -I http://goo.gl/3fG5K HTTP/1.1 301 Moved Permanently Content-Type: text/html; charset=UTF-8 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Mon, 26 Nov 2012 00:11:15 GMT Location: http://alvinalexander.com/linux/linux-teleport-command-cd-improved X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked
The following example shows the output from curl when you don't use the -I
option on the same URL:
$ curl http://goo.gl/3fG5K <HTML> <HEAD> <TITLE>Moved Permanently</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>Moved Permanently</H1> The document has moved <A HREF="http://alvinalexander.com/linux/linux-teleport-command-cd-improved">here</A>. </BODY> </HTML>