Getting just the response code from curl

Something that came up whilst writing some scripts was how to get the response code back from curl. I’m posting this here in case it’s useful!

curl -w %{http_code} -s "" -o /dev/null

Breaking this down;

-w, –write-out <format>

Defines what to display on stdout after a completed and successful operation. We’re just getting http_code but there are other options if you take a look at the man page.

-s, –silent

Silent or quiet mode. Don’t show progress meter or error messages. Makes Curl mute. It will still output the data you ask for,¬†potentially even to the terminal/stdout unless you redirect it.

-o, –output <file>
Write output to <file> instead of stdout. This is just to mute the rest of the output.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s