curl Cheat Sheet
Quick reference for curl: HTTP verbs, headers, authentication, JSON, forms, uploads, downloads, redirects, debugging, retries, and connection controls — with common options and practical examples.
30 commands
Basics
curl <url>Fetch a URL and print the body to stdout.
-L follow redirects; -i include headers; -I HEAD only; -v verbose; -s silent; -S show errors; --compressed decode gzip/brotli
curl -L -s -o website.html https://example.com && curl -sI https://example.comcurl -O <url> / curl -o <file> <url>Download a file: -O keeps the remote name, -o writes to a chosen path.
-O; -o file; --create-dirs; --remove-on-error; -C - resume; --retry N; --retry-delay N
curl -O https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz && curl -C - -O https://releases.example.com/sqldump.sqlHTTP Methods & Headers
curl -X <METHOD> <url>Force a specific HTTP method (POST/PUT/PATCH/DELETE...).
-X POST/PUT/PATCH/DELETE; --request-method; --request-target
curl -X DELETE -s https://api.example.com/users/42 && curl -X POST https://api.example.com/resetcurl -H 'Header: value' <url>Send one or more custom headers (Content-Type, X-API-Key, etc.).
-H 'X-API-Key: ...'; -H repeated; --json (Content-Type + payload); --form -F (multipart)
curl -s -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/json' https://api.example.com/orders/1curl -A <agent> / -e <url>Set the User-Agent string or Referer.
-A 'Mozilla/5.0 ...'; -e 'https://google.com'; --referer alias
curl -sA 'Mozilla/5.0 (X11; Linux)' -e 'https://google.com' https://example.com/articlecurl -i / -D headers.txt / -I <url>-i shows headers inline; -D writes them to a file; -I sends HEAD only.
-i; -D <file>; -I; --dump-header <file>
curl -sI https://api.example.com/health && curl -D headers.txt -o body.json -s https://api.example.com/meAuthentication
curl -u <user>:<password>HTTP Basic auth (with optional password; leave out the colon for prompt).
-u user:pass; --basic; -U readonly specific method
curl -u alice:'P@ssw0rd!' -s https://rest.example.com/private/list && curl -u alice -s https://rest.example.com/mecurl -H 'Authorization: Bearer <token>'Send a Bearer token (also works via --oauth2-bearer).
--oauth2-bearer $TOKEN; --bearer alias (8+)
curl --oauth2-bearer '$GH_TOKEN' -s https://api.github.com/user | jq .logincurl --cert / --key / --cacertUse client certificates / CA bundle for mTLS.
--cert certfile[:password]; --key key; --cacert ca.pem; --capath dir
curl --cert client.p12:P@ss --cacert ca.pem -s https://secure.internal/api && curl --cert cert.pem --key key.pem --cacert ca.pem https://...Data & Form
curl -d '<body>' / -d @file / --data-raw / --data-binarySend a request body (POST/PUT). -d defaults to form encoding; --data-binary preserves bytes.
-d 'a=b&c=d'; --data-raw; --data-binary @f; -G with --data-urlencode builds a query string
curl -s -X POST -d 'name=alice&[email protected]' https://api.example.com/users && curl --data-binary @body.json -H 'Content-Type: application/json' https://api.example.com/notescurl -F 'file=@/path'Send a multipart/form-data upload (the browser's standard upload format).
-F field=value; -F file=@path; -F '[email protected];type=image/png'; --form-string raw
curl -s -F 'avatar=@./photo.png' -F 'name=alice' https://api.example.com/profilecurl -G --data-urlencodeBuild a URL-encoded query string (URL-encode values automatically).
-G --data-urlencode 'q=hello world' --data-urlencode 'limit=10'
curl -sG --data-urlencode 'q=hello world' --data-urlencode 'page=2' https://api.example.com/searchJSON
curl -d @body.json -H 'Content-Type: application/json'Send JSON in the request body.
use --json shortcut (Content-Type + payload in one flag)
curl -s --json @body.json -X POST https://api.example.com/orders && curl --json '{"a":1}' https://api.example.com/xcurl | jq '.'Pipe response into jq for readable / filtered JSON.
jq '. | {name,id}'; jq 'select(.id==42)'
curl -s https://api.github.com/repos/pnpm/pnpm/releases/latest | jq '{tag_name: .tag_name, name: .name, assets: [.assets[].name]}'Cookies & Sessions
curl -b cookies.txt / -c cookies.txtRead cookies (b) / write cookies (c). Pass -j on first call to capture redirects.
-c jar.txt save; -b "k=v" literal; -b / -c /tmp/jar same file
curl -s -c /tmp/jar.txt -o /dev/null https://app.example.com/login && curl -s -b /tmp/jar.txt https://app.example.com/dashboardcurl --cookie-jar / --cookieLong-form aliases of -c / -b; use these in scripts for clarity.
curl --cookie-jar /tmp/jar --cookie /tmp/jar -s https://app.example.com/meDebug
curl -v / -vv / --trace-asciiVerbose handshake trace; --trace dumps bytes sent/received.
-v / -vv / -vvv; --trace-ascii file; --trace file (binary)
curl -v --trace-ascii /tmp/login.trace https://api.example.com/logincurl --nextReset flags between chained requests (avoids 'URL parm 0' and connection leaks).
--next; provides a per-call reset
curl -s -H 'Accept: text/html' https://example.com --next -s -H 'Accept: application/json' https://example.com/apicurl -w '%{http_code}\n'Define a write-out template — useful in scripts to inspect timing or status.
-w 'status=%{http_code} time=%{time_total}\n'; --write-out
curl -s -o /dev/null -w 'status=%{http_code} time=%{time_total}s bytes=%{size_download}\n' https://example.com/healthTransfers & Retries
curl -C - <url>Resume a partial download from where it stopped.
-C -; --continue-at -
curl -C - -O https://releases.example.com/ubuntu-iso.isocurl --retry N --retry-delay S --retry-all-errorsAuto-retry transient errors (network, 5xx, reset).
--retry; --retry-delay; --retry-max-time; --retry-connrefused; --retry-all-errors (8+)
curl --retry 5 --retry-delay 5 --retry-all-errors --max-time 60 -O https://internal.example.com/big.zipcurl --limit-rate <speed> / --max-time <seconds>Cap the bandwidth usage or absolute run time.
--limit-rate 200k; --max-time 30; --connect-timeout 5
curl --limit-rate 1M --max-time 600 -O https://releases.example.com/big.isocurl -T <file> <url>Upload a file via PUT (or HTTP PUT/RESUMABLE, with -C -).
-T file; --upload-file; continue -C -; combine with -H 'Authorization: ...'
curl -T ./dist.tar.gz -H 'Authorization: Bearer $TOKEN' https://uploads.example.com/build/1.4.2.tar.gzConnection
curl --interface <ip> / --dns-serversBind a NIC (use a VPN interface IP) or override DNS — for split DNS debugging.
--interface eth0:0; --dns-servers 1.1.1.1; --resolve 'host:port:ip' overrides per-call
curl --interface 10.99.0.1 -s https://api.internal.example.com && curl --resolve api.internal.example.com:443:127.0.0.1 -s https://api.internal.example.comcurl --http2 / --http3 / --tlsv1.2Negotiate a specific protocol or TLS version.
--http2; --http2-prior-knowledge; --http3 (curl ≥ 7.88); --tls-max 1.3; --no-alpn
curl --http3 -sI https://cloudflare-quic.com && curl --tlsv1.2 -s https://api.example.comcurl --insecure / --cacertSkip or override TLS verification (insecure = debug only).
-k / --insecure; --cacert ca.pem; --capath dir
curl -k --cacert dev-ca.pem -s https://localhost:8443/healthConfig
curl -K config.curlDrive curl from a config file — great for repeatable scripts.
--config file; per-call options
curl -sK - <<'EOF'\nurl = 'https://api.example.com/me'\nheader = 'Authorization: Bearer '$'${TOKEN}'\ncurl --parallel / --parallel-maxRun multiple URLs concurrently from a single curl instance (curl 7.68+).
--parallel; --parallel-immediate; --parallel-max N
curl --parallel --parallel-max 5 -sO https://example.com/img1.png -sO https://example.com/img2.pngMisc
curl --fail-with-body / -f / -fsSLCommon URL-getting idiom for scripts: silent, follow, fail on HTTP errors, output.
-f / --fail; --fail-with-body show body on error; -s silent; -L follow; -S show errors
curl -fsSL -o installer.sh https://get.docker.com && sh installer.shcurl --compressed / --no-compressedRequest gzip, deflate, or brotli with --compressed; saves bandwidth.
--compressed
curl --compressed -s -A 'Mozilla/5.0' https://news.example.com | head -c 200Cheatsheet version 1.0.0
Covers curl 7.88+