3

I want to just get a statusCode from CURL command response.

When I use this command:

curl -I  http://uploadserver.ln/1.mp4

I want to just get 200 rather than this long result:

HTTP/1.1 200 OK
Server: nginx/1.14.0 (Ubuntu)
Date: Sun, 01 Jul 2018 12:47:02 GMT
Content-Type: video/mp4
Content-Length: 1055736
Last-Modified: Sat, 30 Jun 2018 07:58:25 GMT
Connection: keep-alive
ETag: "5b373821-101bf8"
Accept-Ranges: bytes

Can anyone help me?

5

You can use the -w parameter to define the format curl outputs. To get the status code and nothing else, use something like this:

$ curl -s -o /dev/null -w "%{http_code}" http://xxx.xxx.xxx

The output should look like this:

$ curl -s -o /dev/null -w "%{http_code}" https://www.google.com
200

Note, the -o defines that the output for the page will be sent to /dev/null - this way it will only print out the status code and not the page contents.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.