25

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
  • 72,524
  • 21
  • 127
  • 192
soroush
  • 365
  • 1
  • 3
  • 6

1 Answers1

39

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,355
  • 16
  • 54
  • 72
Miuku
  • 690
  • 5
  • 7