The OP wants to know the status code. Often when downloading a file you also want to get a feel of it's size so I'm using curl first to show status code and size of file and then shut off verbose and direct file to the place and name I want:
curl -R -s -S -w "\nhttp: %{http_code} %{size_download}\n" -o /Users/myfiles/the_local_name.html http://archive.onweb.com/the_online_name.html
Then I wait for the finishing of curl
wait ${!}
before I run the next command. The above when used in a script of many commands like above gives a nice response like:
http: 200 42824
http: 200 34728
http: 200 35452
Please note that -o in curl needs to be followed by the full path of the file + name of file. This allows you thusly to save files in a sensible name structure when you d/l them with curl. Also note that -s and -S used together silence the output but does show errors. Note also that -R tries to set the file timestamp to that of the web file.
My answer is based on what @pvandenberk originally suggested, but in addition it actually saves the file somewhere, instead of merely directing to /dev/null.
As for me, I can see from the manual how to get the HTTP status code, but the option -w does not work. I have reported the bug to Apple. – Nicolas Barbulesco – 2015-05-04T17:51:37.817
27
The
– caw – 2017-03-13T03:10:06.357-i
flag, as incurl -i https://www.example.com/
, is probably what you want, as per https://superuser.com/a/514798/190188Why not just something like
curl -IL http://www.example.com | grep "^HTTP\/"
? – St3an – 2019-02-18T07:46:14.017Not to future self: the answer you want is probably Cyril David's (currently in 4th position) – WhiteHotLoveTiger – 2019-06-17T18:08:54.990