Curl Flags Example

Curl has well over two hundred options. Day to day you need about twenty-five, and they fall into a few groups: what to send, what to show, where to save, and how to behave when the network misbehaves.

Last updated . How this page is checked.

The command

curl -sS -L -f -H "Accept: application/json" -o out.json https://httpbin.org/json

What the flags do

FlagWhat it does
-X, --requestSet the method. Rarely needed: -d, -I and -T already choose one.
-H, --headerAdd, replace or remove a request header.
-d, --dataSend a body (form-encoded by default). Makes the request a POST.
--jsonSend a JSON body with the JSON headers set (7.82+).
-F, --formSend a multipart form field or file.
-G, --getPut -d data in the query string of a GET.
-u, --userBasic-auth credentials.
-A, --user-agentSet the User-Agent header.
-b, --cookieSend cookies, or read them from a file.
-c, --cookie-jarSave received cookies to a file.
-i, --includePrint response headers before the body.
-I, --headSend HEAD; print headers only.
-v, --verboseShow the connection, the request and the response headers.
-s, --silentNo progress meter or error messages.
-S, --show-errorWith -s, still print errors.
-w, --write-outPrint variables such as %{http_code} after the transfer.
-o, --outputWrite the body to a named file.
-O, --remote-nameWrite the body to a file named after the URL.
-L, --locationFollow redirects.
-f, --failExit non-zero on HTTP 4xx and 5xx.
-m, --max-timeOverall time limit in seconds.
--connect-timeoutTime limit for establishing the connection.
--retryRetry transient failures.
-x, --proxySend the request through a proxy.
-k, --insecureSkip TLS certificate verification. Avoid.
--compressedAsk for and decode compressed responses.
-K, --configRead options from a file.

How flags combine

Single-letter flags that take no argument can be stacked behind one dash, so -sSL is -s -S -L. A flag that takes a value must come last in such a group, with its value after it: -sSLo file. Flags and the URL can appear in any order. A boolean long option can be switched off again by prefixing no-, as in --no-progress-meter, which is useful for overriding something set in a config file.

Case matters and the pairs are not related: -o and -O, -i and -I, -s and -S, -x and -X, -k and -K, -f and -F all do different things.

curl -sSLf -o page.html https://example.com/
curl -sS -w "%{http_code} %{time_total}s\n" -o /dev/null https://example.com/

A sensible default set for scripts

Interactive use and scripts want different behaviour. In a script, hide the progress meter but keep errors (-sS), treat HTTP errors as failures (-f), follow redirects if the URL may move (-L), and never wait forever (--max-time). Put options you always want in ~/.curlrc, one per line without the leading dashes, and bypass that file for a single command with -q as the first argument.

curl -fsSL --connect-timeout 5 --max-time 30 --retry 3 https://example.com/install.sh -o install.sh

Common mistakes

  • -X does not add a body or change behaviour; it only rewrites the method word. -X POST without data is an empty POST.
  • -s alone hides error messages too. Always pair it with -S.
  • Options differ between versions. Run curl --version, and curl --help all for the list your build supports.

Related curl examples

More under Reference

References

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

What are the most common curl flags?

-X for the method, -H for headers, -d for a request body, -i or -v to see headers, -o or -O to save output, -L to follow redirects, -u for credentials and -s to silence the progress meter.

Can I combine curl flags?

Yes. Single-letter flags without arguments can be written together, for example -sSL. A flag that takes a value must be last in the group.

How do I see all curl options?

Run curl --help all for the complete list, or man curl for the manual with a description of each option.