What it does
curl URL prints the answer of a server. With options you choose the method (-X), send headers (-H) and data (-d), follow redirects (-L), save to a file (-o), and see headers (-I, -i) or the full talk with the server (-v).
It is the tool to test a web server on the RHCSA exam (curl http://localhost) and the daily tool for REST APIs in DevOps.
curl has more than 250 options. This page lists the ones admins use most; see all with curl --help all.
How to write it
curl [OPTION]... URL...Options 57
Most used
Request
Output
Connection
TLS
Errors and others
Nothing matches this filter.
Examples 12
$ run as a normal user# run as root (or with sudo)
1Test a web server
curl http://localhostRHCSA: check that httpd serves the page.
2Only the headers
curl -I https://s0sta.com HTTP/2 200 content-type: text/html; charset=UTF-8 strict-transport-security: max-age=31536000Check status code and security headers.
3Only the status code
curl -s -o /dev/null -w '%{http_code}\n' https://s0sta.com 200Good for health checks and scripts.
4Follow redirects
curl -sIL http://s0sta.com | grep -iE '^(HTTP|location)'Shows the chain http → https.
5Download a file
curl -LO https://example.com/tool.tar.gzSaves as tool.tar.gz. Check the checksum afterwards.
6Call a JSON API
curl -s -H "Authorization: Bearer $TOKEN" https://api.example.com/v1/servers | jq '.[].name'Keep tokens in variables or files, not in the history.
7Send JSON with POST
curl -s -X POST -H 'Content-Type: application/json' -d '{"name":"web1"}' https://api.example.com/v1/serversOr shorter:
--json '{"name":"web1"}'.8Test a site on a new server before the DNS change
curl -sI --resolve s0sta.com:443:203.0.113.20 https://s0sta.comUses the new IP with the real name and certificate.
9See the TLS handshake and certificate
curl -sv https://s0sta.com -o /dev/null 2>&1 | grep -E 'SSL connection|subject:|expire date'Check TLS version and expiry.
10Measure response times
curl -s -o /dev/null -w 'dns %{time_namelookup}s connect %{time_connect}s total %{time_total}s\n' https://s0sta.comFind out if DNS, the network or the app is slow.
11Fail in a script on HTTP errors
curl -fsS https://example.com/health || echo "health check failed"-f makes 404/500 an error (exit code 22).
12Check from inside a container network
podman run --rm registry.access.redhat.com/ubi10/ubi curl -sI http://web:8080Tests service-to-service access.
Nothing matches this filter.
Watch out
-kturns off certificate checks: never in production scripts.curl URL | bashruns code from the internet without a check. Download, read, then run.- Passwords with
-u user:passshow up in the process list and history.
Files
~/.curlrc- Default options.
~/.netrc- Login data for -n.
Exit codes
0 :: Done. 6 :: Could not resolve the host. 7 :: Could not connect. 22 :: HTTP error with -f. 28 :: Timeout. 35 :: TLS handshake failed. 60 :: The certificate could not be checked.