tips
71 tips Curl
One command, setting or habit at a time about Curl: what it does, the line to copy and a caveat or two.
Downloads 17
-
Put url and output pairs in one file and fetch them all with one command.
url = "https://example.com/data/latest.json" -
Store where a file came from in its extended attributes, so you can look it up later.
curl --xattr -O https://example.com/tools/file.tar.gz -
Space out a series of requests so an API or small server is not hit all at once.
curl --rate 2/s -O 'https://example.com/archive/page[1-20].html' -
Keep the file you already have and let the new download land under a numbered name.
curl --no-clobber -O https://example.com/report.pdf -
Stop a transfer that crawls along at almost nothing, without capping the total time.
curl --speed-limit 1000 --speed-time 30 -O https://example.com/images/big.iso -
Find out which file name curl chose, so the next step in a script can use it.
file=$(curl -fsSLOJ -w '%{filename_effective}' "https://example.com/download?id=4812") -
Send a URL with square brackets or curly braces exactly as you typed it.
curl -s 'https://example.com/api/items?ids[0]=4' -
Starts every download on the command line at once instead of waiting for each one to finish.
curl --parallel --remote-name-all \ -
Stores a download's ETag and sends it next time, so an unchanged file is not fetched again.
curl --etag-save etag.txt --etag-compare etag.txt \ -
Creates the missing folders of a download path so you do not need a separate mkdir.
curl --create-dirs -o /mnt/user/appdata/<app>/downloads/2026/data.zip \ -
Downloads a file only when the server's copy is newer than your local file.
curl -R -z feed.xml -o feed.xml https://example.com/feed.xml -
Expands ranges and lists inside a URL so curl downloads a whole numbered series in one command.
https://example.com/file[1-100].txt -
Makes curl skip a download when a file with that name already exists locally.
curl --skip-existing --create-dirs --parallel --remote-name-all \ -
Caps the speed of a curl download or upload so the rest of the network stays usable.
curl -L --limit-rate 2M -O https://example.com/images/debian.iso -
Saves a curl download with the filename from the Content-Disposition header instead of the URL.
curl -L -OJ --output-dir ~/Downloads "https://example.com/download?id=4812" -
Downloads a chosen byte range, such as only the end of a large file.
curl -r 0-99 https://example.com/big.log -
Continues a partly downloaded file from its current size instead of restarting.
curl -C - -O https://example.com/big.iso
Requests 13
-
Send a multipart form with a file field, a text field and a content type.
curl -F '[email protected];type=image/jpeg' \ -
Keep a POST a POST when curl follows a 301, 302 or 303.
curl -L -d 'name=test' https://example.com/old -
Know when -X helps and when it quietly breaks a request.
curl -X DELETE https://api.example.com/items/42 -
Append query string parts to a URL that already has some, with encoding done for you.
curl --url-query 'q=hello world' \ -
Lets curl hold variables and insert them, correctly escaped, into the URL or request body.
curl --variable [email protected] \ -
Splits one curl command into separate requests that each keep their own options.
curl https://example.com/ --next -d 'name=test' https://example.com/api/items -
Uploads a local file to a URL with a PUT request, with the file name added for you.
curl -T backup.tar.gz https://example.com/uploads/ -
Sends a request for your real domain to another server, keeping the name for TLS.
curl -I --connect-to example.com::192.168.1.20: https://example.com/ -
Sends a JSON body together with the matching content-type and accept headers.
curl --json '{"name":"test","qty":2}' https://api.example.com/items -
Strips a header curl adds by default or sends one with an empty value.
curl -v -H 'User-Agent:' -H 'Accept:' -H 'X-Empty;' https://example.com/ -
Saves cookies from one request and sends them with the next one.
curl -c jar.txt https://example.com/login-page -
Posts a file byte for byte, which -d does not do with line breaks.
curl --data-binary @payload.json \ -
Adds correctly encoded parameters to a GET request instead of building the URL by hand.
curl -G https://example.com/search \
Access and security 11
-
Pin the server's public key, so even a valid certificate with another key is refused.
openssl x509 -in server.pem -pubkey -noout \ -
Force a TLS version range to see which versions a server accepts.
curl -sv -o /dev/null --tlsv1.2 --tls-max 1.2 https://example.com/ 2>&1 | grep 'SSL connection' -
Use your own certificate and key to pass mutual TLS checks on an API or proxy.
curl --cert client.pem --key client.key https://api.example.com/status -
Keep an HSTS cache file so curl upgrades plain http URLs for sites that asked for it.
curl --hsts ~/.curl-hsts https://example.com/ -
See every certificate in the chain, with subject, issuer and dates, from one curl command.
curl -s -o /dev/null -w '%{num_certs}\n%{certs}' https://example.com/ | grep -E '^[0-9]|Subject:|Issuer:|Expire' -
Limits curl and its redirects to HTTPS so a link can never downgrade to plain HTTP.
curl --proto =https --proto-redir =https -L -o install.sh https://example.com/install.sh -
Lets curl take the login for a host from a locked-down .netrc file, so no password shows in the command.
password secret -
Checks whether a password is in known breaches by sending only 5 characters of its SHA-1 hash.
curl -s "https://api.pwnedpasswords.com/range/${H:0:5}" | grep -i "${H:5:35}" -
Passes secrets to curl through stdin instead of visible command-line arguments.
printf 'header = "Authorization: Bearer %s"\n' "$API_TOKEN" | curl -K - https://api.example.com/me -
Verifies a server against your own certificate authority instead of skipping verification.
curl --cacert /etc/ssl/homelab-ca.pem https://nas.lan:8443/ -
Makes curl ask for the password so it never appears in history or the process list.
curl -u alice https://example.com/private/
Scripting 7
-
Get all write-out values at once and pick fields with jq.
curl -s -o /dev/null -w '%{json}' https://example.com/ | jq . -
Stay quiet on success and print the exit code and error text on failure.
curl -s -o /dev/null \ -
Write the status line of each check to a log file, while the body goes elsewhere.
curl -s -o /dev/null \ -
Makes curl exit with code 22 on an HTTP error but still prints the server's error message.
|| { echo "request failed: $resp" >&2; exit 1; } -
Prints the final URL after following every redirect.
curl -Ls -o /dev/null --max-redirs 5 -w '%{url_effective} (%{num_redirects} hops)\n' http://example.com/ -
Aborts a request that takes too long to connect or to finish.
curl --connect-timeout 5 --max-time 30 -fsS https://example.com/api -
Repeats a failed request several times, even on errors curl normally treats as final.
curl --retry 5 --retry-delay 2 --retry-all-errors -fsS -O https://example.com/file.tgz
Headers and timing 6
-
Writes a readable log of everything curl sends and receives, headers and body included.
curl --trace-ascii - https://example.com/ -
The Retry-After header sets how long a client should wait, and curl --retry follows it.
Retry-After: 120 -
Keep the headers of a download in a separate file while the body goes to its own file.
curl -sL -D headers.txt -o page.html https://example.com/ -
Read one response header in a script without grep, cut or carriage returns.
curl -s -o /dev/null -w '%header{cache-control}\n' https://example.com/ -
Fetches only the response headers of a URL, to check redirects, status codes and caching.
curl -I https://example.com -
Prints only the HTTP status code and response time of a URL.
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://example.com
Network and DNS 6
-
Check that a site answers on both address families, not just the one your machine prefers.
curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ -
Send both the request and the name lookup through a SOCKS proxy, so DNS does not leak.
curl -x socks5h://localhost:1080 https://intranet.example.com/ -
Let one curl command resolve names through a DoH server instead of the system resolver.
curl --doh-url https://dns.quad9.net/dns-query \ -
Shows the negotiated HTTP version and lets you force an older one for comparison.
curl -sI --http2 -o /dev/null -w '%{http_version}\n' https://example.com/ -
Forces a request to leave through a specific interface or source address.
curl --interface wg0 -s -o /dev/null -w '%{local_ip}\n' https://example.com/ -
Requests compressed content and shows from the headers whether the server provides it.
curl -s --compressed -D - -o /dev/null https://example.com/ | grep -i '^content-encoding'
Safe scripts 5
-
Make a multi URL curl command exit with an error as soon as one transfer fails.
curl -fsS --fail-early \ -
Make a script behave the same on every machine, whatever the local curl config says.
curl -q -fsS https://example.com/api/status -
Stops curl from downloading a file that is larger than the size limit you set.
curl --max-filesize 50M -O https://example.com/blocklist.txt -
Removes the output file when a curl transfer fails, so no half-downloaded file is left to use.
curl --fail --remove-on-error -o /mnt/user/appdata/<app>/list.txt https://example.com/list.txt -
Makes curl fail on HTTP errors with an exit code while still printing error messages.
curl -fsS https://example.com/health || echo "check failed"
Protocols and network 2
-
Query a DICT server for word definitions straight from the terminal.
curl dict://dict.org/d:latency -
Lists the protocols and features compiled into the curl you are running.
curl -V | grep -E '^(Protocols|Features)'
Prowlarr and indexers 2
-
Read Prowlarr's health checks and disabled indexers from a script, with the API key in a header.
curl -fsS -H "X-Api-Key: $KEY" http://localhost:9696/api/v1/health | jq -r '.[] | "\(.type): \(.message)"' -
Queries one Prowlarr indexer directly as a Torznab or Newznab feed with curl.
curl "http://192.168.1.x:9696/11/api?t=caps&apikey=YOUR_API_KEY"
Web development 2
-
Get the libcurl options behind a command line, as a starting point for your own code.
curl --libcurl code.c -s -H 'Accept: application/json' https://example.com/api/items -
Copies every request still visible in a filtered Network list as cURL commands.
method:POST
Nothing in this filter yet.