Curl - Display HTTP return code using the -w or --write-out "%{http_code}" option
by
Jeremy Canfield |
Updated: June 24 2022
| Curl articles
The curl command with the -w or --write-out option followed by "%{http_code}" can be used to display the HTTP return code of the request. In this example, the request to get the index.html page from the www.example.com web server returned HTTP code 200 (OK).
~]# curl --write-out "%{http_code}" http://www.example.com/index.html
<html>
<body>
Hello World
</body>
</html>
200
You may want to also use the -s or --silent flag and the -o /dev/null option to suppress the response body output. Now, only the HTTP response code is returned.
~]# curl --silent --output /dev/null --write-out "%{http_code}" http://www.example.com/index.html
200
In this example, 404 (not found) is returned when attempting to get foo.html from the www.example.com web server, because there is no such file as foo.html on the www.example.com web server.
~]# curl --silent --output /dev/null --write-out "%{http_code}" http://www.example.com/foo.html
404
Did you find this article helpful?
If so, consider buying me a coffee over at 
Comments
October 20 2025 by Rachael
4M Dental Implant Center
3918 L᧐ng Beach Blvd #200, ᒪong Beach,
CА 90807, United Stɑtes
15622422075
Advanced Whitening
October 20 2025 by Clay
4M Dental Implant Center
3918 Long Beach Blvdd #200, ᒪong Beach,
CA 90807, United States
15622422075
oral vitality (https://3ba8u.mssg.me/)
October 20 2025 by Kayleigh
4M Dental Implant Center
3918 ᒪong Beach Bllvd #200,ᒪong Beach,
CA 90807, United States
15622422075
e-dentistry
October 23 2025 by Jennie
Refresh Rnovation Southwest Charlotte
1251 Arrow Pine Ɗr c121,
Charlotte, NC 28273, United Ѕtates
+19803517882
And Upgrades Heating Conditioning Air - Jumpy-Albatross-Ꭰ65.Notion.Site,
October 29 2025 by Aida
Cabinet IQ Austin
8305 Stae Hwy 71 #110, Austin,
TX 78735, United Ѕtates
+12542755536
Schedule