The command
curl -sS -L -f -H "Accept: application/json" -o out.json https://httpbin.org/json
What the flags do
| Flag | What it does |
|---|---|
-X, --request | Set the method. Rarely needed: -d, -I and -T already choose one. |
-H, --header | Add, replace or remove a request header. |
-d, --data | Send a body (form-encoded by default). Makes the request a POST. |
--json | Send a JSON body with the JSON headers set (7.82+). |
-F, --form | Send a multipart form field or file. |
-G, --get | Put -d data in the query string of a GET. |
-u, --user | Basic-auth credentials. |
-A, --user-agent | Set the User-Agent header. |
-b, --cookie | Send cookies, or read them from a file. |
-c, --cookie-jar | Save received cookies to a file. |
-i, --include | Print response headers before the body. |
-I, --head | Send HEAD; print headers only. |
-v, --verbose | Show the connection, the request and the response headers. |
-s, --silent | No progress meter or error messages. |
-S, --show-error | With -s, still print errors. |
-w, --write-out | Print variables such as %{http_code} after the transfer. |
-o, --output | Write the body to a named file. |
-O, --remote-name | Write the body to a file named after the URL. |
-L, --location | Follow redirects. |
-f, --fail | Exit non-zero on HTTP 4xx and 5xx. |
-m, --max-time | Overall time limit in seconds. |
--connect-timeout | Time limit for establishing the connection. |
--retry | Retry transient failures. |
-x, --proxy | Send the request through a proxy. |
-k, --insecure | Skip TLS certificate verification. Avoid. |
--compressed | Ask for and decode compressed responses. |
-K, --config | Read 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
-Xdoes not add a body or change behaviour; it only rewrites the method word.-X POSTwithout data is an empty POST.-salone hides error messages too. Always pair it with-S.- Options differ between versions. Run
curl --version, andcurl --help allfor the list your build supports.
Related curl examples
How to Use Curl
Curl is a command-line program that makes network requests and prints what comes back.
Curl -d Flag Example
-d looks like "send this data", but it does three things at once and quietly edits file input.
Curl Send Header Example
-H adds a header line to the request.
Curl Timeout Example
By default curl puts no limit on how long a transfer may take, so one silent server can hang a script indefinitely.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Reference
References
- curl man page — Every option, with the version it was added in.
- curl: options and versions — A table of which release introduced each command-line option.
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.