4

Please i want to use the cURL command in linux OS to return as a result just the http response code which is "200" if it is okey

am using that command:

curl -I -L domain.com

but this is returning for me a full text like this

HTTP/1.1 **200** OK
Date: Thu, 27 Feb 2014 19:32:45 GMT
Server: Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.4.19
X-Powered-By: PHP/5.4.19
Set-Cookie: PHPSESSID=bb8aabf4a5419dbd20d56b285199f865; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Content-Type: text/html

so please i just need the response code and not the whole text

Regards

2 Answers 2

10
curl -s -o out.html -w '%{http_code}' http://www.example.com
Sign up to request clarification or add additional context in comments.

5 Comments

this is returing the whole source of the index
ohhh yes . thanks alot i saw the out.html .. not the result on the terminal. thanks sir
@user3178889: If you are satisfied with Sabuj's answer. Please click the check mark in front of his answer to accept it. This way it is clear that your question was successfully answered.
I wanted to pull a website html source as a text file, changed out.html to out.txt and the above command worked. Thanks!
This is prohibitively slow if the body is large.
1

Running the following will supress the output so you won't have any cleanup.

curl -s -o /dev/null -w '%{http_code}' 127.0.0.1:80

Example above uses localhost and port 80

1 Comment

Yes, it provides the http code (i.e. 200, etc.) root@70349a8eaf2c:/# curl -s -o /dev/null -w '%{http_code}' 127.0.0.1:80 200root@70349a8eaf2c:/# root@70349a8eaf2c:/#

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.