For $url being the placeholder for an URL.

curl can retrieve headers for an url using

#> curl -sI -L $url.

wget can do the same using:

#> wget --server-response --spider $url

fetch is the third command line downloading tool that I am aware of.

Can it also get only headers?

  • According to freeBSD man pages ( freebsd.org/cgi/man.cgi?fetch(1) ), this tool doesn't seem to allow you to get the headers only.
    – user264413
    Jan 16, 2018 at 9:06
  • Does it really matter? You already have two tools performing the requested operation, do you need a third one? Jan 16, 2018 at 9:23
  • Because this code in question is for deployment on systems that are guaranteed to have at least one of wget, curl or fetch. Jan 16, 2018 at 9:26
  • Considering headers are always separated from body by a single empty line, are you able to pass the tool output through another tool that will drop everything after the headers (e.g. sed)?
    – B Layer
    Jan 16, 2018 at 10:03
  • @BLayer no, because the total response (including the body) might be very large. (where as the headers will be very small) Jan 16, 2018 at 10:04

1 Answer 1


If you have a way to fetch the full HTTP page, headers and body, then you could just use this:

fetch ... | sed '/^\r$/q'

Because headers are always separated from body by CRLF this will terminate after retrieving the headers.

  • Thanks. So is it possible to tell fetch to use HEAD ? It seems like otherwise the first part is not connected by much to the second. Jan 18, 2018 at 5:27
  • You said "other options are...substituting HEAD for GET". When someone says something's an "option" that typically means it's possible. I was just trying to move important information out of the comments into an answer where other people are more likely to see it. If HEAD is not really an option then I need to remove it from my answer.
    – B Layer
    Jan 18, 2018 at 6:56
  • To my knowledge you can't trigger HEAD directly from the command line? the "..." in your quotes covers the part where is links to another post detailing a method where possibly HEAD can be used. This question is about fetch however, so if it is not usable with fetch then I'm not sure it is worth highlighting. I wouldn't know if it was usable by fetch (thus this question). I assume as the answerer you are more familiar with fetch than I am. Jan 18, 2018 at 9:01
  • I don't have access to fetch. I posted my answer as a hopefully helpful suggestion (based on a sound principle) that you could look into since no other answers have been offered. I can't tell from looking at the man page whether full HTTP message is returned.
    – B Layer
    Jan 18, 2018 at 11:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .