Network and remote access

Command curl

Send HTTP requests and download data

Linux · Bash examples · commands run on the selected server

When to use curl

Use curl to inspect HTTP responses, download a resource or call an API from the server. Separate transport success from application success, set sensible timeouts and keep authentication tokens out of saved command examples.

Syntax

curl [PARAMETERS] URL

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-I
Request HTTP headers only, using the HEAD method.
-f
Return an error for HTTP status codes 400 and above.
-L
Follow redirects; -o specifies the result file.

Usage examples

Check site headers

curl -I https://example.com

A header-only request is made; some services handle this differently from a normal content request.

Download file with processing of HTTP errors

curl --fail --location --output ./page.html https://example.com

Redirects are followed and the response body replaces the named local file; HTTP error statuses cause failure.

Request JSON with time limit

curl --fail --max-time 15 -H 'Accept: application/json' https://example.com/api/status

A JSON response is requested with a bounded overall duration; the endpoint must actually provide that API.

Notes and limitations

  • With HTTPS the certificate is verified by default; do not disable checking via -k without a separate reason.
  • Do not place real tokens or passwords in command history and do not run downloaded scripts without verification.

Common questions and troubleshooting

Why does curl succeed when the server returns an error page?

Without the failure option, receiving an HTTP error response can still count as a successful transfer. Inspect both HTTP status and command exit status.

Should I disable certificate verification to fix HTTPS?

Do not bypass trust as a routine fix. Check the hostname, system time, server certificate chain and trusted CA configuration instead.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man curl.