curl -sSi <URL> | sed '/^\r$/q'

Get HTTP headers using curl, but still perform a GET

Similar to the following: curl -I <URL> but curl -I performs a HEAD request, which can yield different results.

By: cbuckley
2014-08-27 15:47:05

These Might Interest You

  • I is for headers only s is for silence curl -Is outputs ONLY headers the pipe and grep is to filter them to Modified only.. Show Sample Output

    curl -Is | grep Mod
    Gunni · 2012-05-01 21:42:42 0
  • Some sites running on basic web servers don't support the HEAD request, so using "curl -I" on them doesn't work. This will automatically try "curl -I" at first and if that fails with a 4xx or 5xx status code, it falls back to "curl -i" and prints only the headers from that.

    curlh() { x="$(curl -Is -w '%{http_code}' "$@")"; if [[ "$(tail -n 1 <<< "$x")" == [45]* ]]; then curl -is "$@" | awk '{ if (!NF) { exit }; print }'; else head -n -1 <<< "$x"; fi; }
    nyuszika7h · 2017-07-10 12:29:00 0

  • 17
    curl -I
    sunkencity · 2009-02-05 14:47:59 0
  • Watches the headers of a curl, following any redirects and printing only the HTTP status and the location of the possible redirects. Show Sample Output

    watch 'curl -s --location -I | grep -e "\(HTTP\|Location\)"'
    theist · 2012-04-23 17:05:29 0
  • There's been a similar Futurama thing around for a while, which grabs a quote from the /. headers [curl -Ism3 | egrep "^X-(F|B|L)" | cut -d \- -f 2- | fmt -w $(tput cols)]. Same deal, but more likely to stop working when someone forgets to pay the bill on the domain. Until then: Cave Johnson! Show Sample Output

    curl -s | grep quote_main | cut -d \> -f 2- | fmt -w $(tput cols)
    ColOfNature · 2011-05-06 01:28:40 0
  • // This is description for the old command: Unfortunately we to encode the URL. It can't be done with bash (without building it ourselves) so I used Perl? Example with Perl: curl -s`perl -MURI::Escape -e "print uri_escape('');"` Example without Perl: curl Most urls doesn't use & and ? anymore (SEO etc) so in most cases you can just use the simple version. :) Show Sample Output

    curl -s "[long_url]"
    Josso · 2009-12-07 18:52:04 2

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: