I, multiple times per day, find myself wanting to find out what headers I get back on a URL but I don't care about the response payload. The command to use then is:

curl -v https://www.peterbe.com/ > /dev/null

That'll print out all the headers sent and received. Nice and crips.

So because I type this every day I made it into a shortcut script

cd ~/bin
echo '#!/bin/bash
> set -x
> curl -v "$@" > /dev/null
> ' > c
chmod +x c

If it's not clear what the code looks like, it's this:


#!/bin/bash
set -x
curl -v "$@" > /dev/null

Now I can just type:

c https://www.peterbe.com

Or if I want to add some extra request headers for example:

c -H 'User-Agent: foobar' https://www.peterbe.com

Comments

Post your own comment
Chris Adams

I did that a lot but now I just `pip install --user httpie`. It has the nice default of not dumping binary data to the console and pretty-printing text responses (no more compressed HTML or JSON blobs) and "http --print h …" will always print only the headers.

James Edward Gray II

curl -I …

Peter Bengtsson

The server might respond differently if given a HEAD request.

James Socol

`curl -i`, doesn't default to HEAD and includes headers in the output.

Jarod McBride

Peter, thanks for the post. What's the difference you get from the above as opposed to running curl -v -I http://www.peterbe.com/ ?

Peter Bengtsson

First of all, the difference is that "curl -v" is 7 characters. Just "c" is 1 character :)
This matters if you type it a lot.

Also, the -I means it does a HEAD request and the server might respond differently. For example the Content-Length header might be wrong/different.

Your email will never ever be published.

Previous:
An AngularJS directive with itself as the attribute September 3, 2014 AngularJS, JavaScript
Next:
Premailer on Python 3 October 8, 2014 Python
Related by category:
set -ex - The most useful bash trick of the year August 31, 2014 Linux
brotli_static in Nginx November 8, 2024 Linux
Be very careful with your add_header in Nginx! You might make your site insecure February 11, 2018 Linux
Linux tip: du --max-depth=1 September 27, 2007 Linux
Related by keyword:
How post JSON with curl to an Express app April 15, 2020 Node, JavaScript
redirect-chain - Getting a comfortable insight input URL redirects history February 14, 2020 Python
How to test if gzip is working on your site or app August 20, 2015 Linux, Web development
How to NOT start two servers on the same port June 11, 2018 Linux, Web development