Curl HEAD Request Example

HEAD asks for the headers a GET would return and nothing else. It is how you check that a URL exists, how big a download is, or when a file last changed, without transferring it.

Last updated . How this page is checked.

The command

curl -I https://httpbin.org/get

What the flags do

FlagWhat it does
-ISend HEAD and print the response headers. Long form: --head.
-LFollow redirects, printing the headers of every hop.
-sHide the progress meter when piping the headers elsewhere.

What you can learn from headers alone

The status line tells you whether the resource is there. Content-Length is the size of the body you did not download, Content-Type is its format, and Last-Modified and ETag let you decide whether a cached copy is still current. With -L you see each redirect and where it points.

curl -sI https://example.com/installer.dmg | grep -i -E "^(HTTP|content-length|last-modified)"

# every hop of a redirect chain
curl -sIL http://example.com/old-path | grep -i -E "^(HTTP|location)"

When HEAD lies

A server is supposed to answer HEAD exactly as it would GET, minus the body. Many do not. Application routes that only register a GET handler return 405 or 404 to HEAD, some CDNs omit Content-Length, and dynamic pages may report different headers because the body was never generated. If a HEAD result looks wrong, confirm it with a GET that discards the body.

# headers from a real GET, body thrown away
curl -s -o /dev/null -D - https://httpbin.org/get

Checking a list of URLs

Because it transfers no body, HEAD is the economical way to audit many links at once. Print the status code and the URL for each with -w, and let xargs run several requests in parallel. Anything that is not a 200 is worth a second look with a full GET, for the reason above.

printf '%s\n' https://httpbin.org/status/200 https://httpbin.org/status/404 \
  | xargs -P 4 -I{} curl -s -I -o /dev/null -w "%{http_code} {}\n" {}

Common mistakes

  • Never write -X HEAD. It changes only the method name, so curl still waits for a body that will not come and either hangs or reports a transfer error. -I is the correct flag.
  • -I cannot be combined with -d. Curl refuses to choose between HEAD and POST. To send query data on a HEAD request, add -G so the data moves into the URL.
  • Header names are case-insensitive, and HTTP/2 always sends them in lower case, so match with grep -i.

Related curl examples

More under Methods

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

How do I send a HEAD request with curl?

Use the -I flag (capital i), for example curl -I https://example.com. Curl sends a HEAD request and prints only the response headers.

Why does curl -X HEAD hang?

Because -X only renames the method. Curl still expects a response body, which a HEAD response never has. Use -I instead.

How do I get just the HTTP status code with curl?

Use curl -s -o /dev/null -w "%{http_code}" URL, adding -I if you want to avoid downloading the body.