30

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?

HBruijn
  • 77,029
  • 24
  • 135
  • 201
soroush
  • 415
  • 1
  • 5
  • 6

1 Answers1

46

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.

slm
  • 7,615
  • 16
  • 56
  • 76
Miuku
  • 760
  • 6
  • 7