1

Currently I am experimenting with curl flags, looking how to get only the response headers, follow the redirection if any, encryption and authentication used and the round trip time.

What flag should I use to hide/disable the HTML body in the output?

3 Answers 3

2

How to make curl disable html output

Use the -s flag (for silent operation) and redirect stout (>) to (eg) /dev/null (or, if you're on Windows, simply NUL)

This, inc combination with -D <file> (aka --dump-header) may give you the output you are looking for.

The curl manpage has more information on the command-line options which may be helpful.

Example

$ curl -s https://superuser.com -D su.txt > /dev/null
$ less -FX su.txt
HTTP/2 200 
date: Sun, 25 Feb 2018 17:24:30 GMT
content-type: text/html; charset=utf-8
x-frame-options: SAMEORIGIN
x-request-guid: e147da19-7cc9-42cd-8706-4204fd64d4a9
strict-transport-security: max-age=15552000
content-security-policy-report-only: default-src https: wss: data: blob: 'unsafe-eval' 'unsafe-inline'; report-uri https://stackoverflow.report-uri.io/r/default/csp/reportOnly
accept-ranges: bytes
via: 1.1 varnish
x-served-by: cache-lcy19224-LCY
x-cache: MISS
x-cache-hits: 0
x-timer: S1519579470.439587,VS0,VE88
vary: Fastly-SSL
x-dns-prefetch-control: off
set-cookie: prov=d007391b-afc2-4717-282a-287f18827242; domain=.superuser.com; expires=Fri, 01-Jan-2055 00:00:00 GMT; path=/; HttpOnly
cache-control: private
content-length: 101543
3
  • 1
    What about a Windows environment that uses git bash to curl ?
    – user876358
    Feb 25, 2018 at 17:42
  • Windows' equivalent to /dev/null is simply NUL; I assume git bash will respect that but cannot test at the minute. I have updated my answer to include that.
    – bertieb
    Feb 25, 2018 at 17:48
  • 2
    In addition, some quick searches indicates that git bash implements /dev/null, so /dev/null may work in that case!
    – bertieb
    Feb 25, 2018 at 17:50
2

You can discard the body while still keeping the headers by telling curl to dump them on stdout:

$ curl -D/dev/stdout -o/dev/null -s https://superuser.com
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
X-Frame-Options: SAMEORIGIN
X-Request-Guid: a599d44b-705c-4615-a8d8-80c7614bd64f
...
  • -D/dev/stdout: dump the headers on standard output
  • -o/dev/null: discard the body
  • -s: disable the progress meter
1
  • 1
    More people should document what the command options mean in their answers like you have.
    – jmrah
    Jan 26, 2019 at 0:38
2

Perharps you can use the -I option to show document info only.

curl -I www.google.com

HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Fri, 22 May 2020 11:21:37 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Expires: Fri, 22 May 2020 11:21:37 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2020-05-22-11; expires=Sun, 21-Jun-2020 11:21:37 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=204=ijCC6L4JERmyB5I14nFMLKl91R8H5gD5thzU43L_s0AFuYDaVwmeYy4X3Sc_FHoY24AXdfpXOnpBNZsKTnlX612_tnnafOlsAThO6K3fXfRuyhU_o5_jVL3la6AK_fryMqYL5ErPmPoxX1-dwq-mQimbqUjY69n_JJYEGct5EuU; expires=Sat, 21-Nov-2020 11:21:37 GMT; path=/; domain=.google.com; HttpOnly

See more curl options by typing curl -h in your terminal

You must log in to answer this question.