Skip to main content

curl Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for curl command-line HTTP client

Curl is a versatile command-line tool for transferring data using various protocols including HTTP, HTTPS, FTP, and more. This cheatsheet covers common use cases from simple downloads to complex API interactions with authentication and custom headers.

Basic Requests

Make simple HTTP requests.

CommandDescription
curl urlGET request
curl -o file urlSave to file
curl -O urlSave with original name
curl -s urlSilent mode
curl -v urlVerbose output
curl -I urlHeaders only (HEAD)
curl -L urlFollow redirects

HTTP Methods

Use different HTTP request methods.

CommandDescription
curl -X GET urlGET request
curl -X POST urlPOST request
curl -X PUT urlPUT request
curl -X DELETE urlDELETE request
curl -X PATCH urlPATCH request
curl -X OPTIONS urlOPTIONS request

POST Data

Send data with POST requests.

CommandDescription
curl -d "data" urlPOST form data
curl -d @file urlPOST from file
curl --data-urlencode "k=v" urlURL encode data
curl -F "file=@path" urlUpload file
curl -F "field=value" urlMultipart form

JSON Data

Work with JSON APIs.

CommandDescription
curl --json '{"key":"value"}' urlPOST JSON
curl --json @data.json urlPOST JSON from file
echo '{}' | curl --json @- urlPOST JSON from stdin
curl -d '{"key":"value"}' -H "Content-Type: application/json" urlPOST JSON (older curl)
curl -H "Accept: application/json" urlRequest JSON
curl url | jqParse JSON response

Headers

Set custom HTTP headers.

CommandDescription
curl -H "Header: Value" urlAdd header
curl -H "Authorization: Bearer token" urlAuth header
curl -H "Content-Type: text/xml" urlContent type
curl -A "User-Agent" urlUser agent
curl -e "referer" urlReferer header

Authentication

Handle various authentication methods.

CommandDescription
curl -u user:pass urlBasic auth
curl -u user urlPrompt for password
curl --digest -u user:pass urlDigest auth
curl --ntlm -u user:pass urlNTLM auth
curl -H "Authorization: Bearer token" urlBearer token
curl --oauth2-bearer token urlOAuth2 bearer

Cookies

Send and receive cookies.

CommandDescription
curl -b "name=value" urlSend cookie
curl -b cookies.txt urlSend from file
curl -c cookies.txt urlSave cookies
curl -b cookies.txt -c cookies.txt urlRead and save

SSL/TLS

Handle HTTPS and certificates.

CommandDescription
curl -k urlIgnore SSL errors
curl --insecure urlIgnore SSL errors
curl --cacert ca.crt urlUse CA cert
curl --cert client.crt urlClient cert
curl --key client.key urlClient key
curl --cert client.pem:pass urlCert with password

Proxy

Route requests through proxies.

CommandDescription
curl -x proxy:port urlHTTP proxy
curl -x socks5://proxy:port urlSOCKS5 proxy
curl --proxy-user user:pass urlProxy auth
curl --noproxy "*.local" urlBypass proxy

Download

Download files and resume transfers.

CommandDescription
curl -o file urlSave to file
curl -O urlUse remote filename
curl -O url1 -O url2Multiple files
curl -C - -O urlResume download
curl --limit-rate 1M urlLimit speed
curl -# urlProgress bar

Upload

Upload files to servers.

CommandDescription
curl -T file urlUpload file (PUT)
curl -F "file=@path" urlForm upload
curl -F "file=@path;type=image/png" urlWith content type
curl --upload-file file urlUpload file

FTP

Work with FTP servers.

CommandDescription
curl ftp://server/fileDownload file
curl -T file ftp://server/Upload file
curl -u user:pass ftp://server/FTP with auth
curl --ftp-ssl ftp://server/FTP over SSL
curl ftp://server/ --list-onlyList directory

Timeouts

Control connection timing.

CommandDescription
curl --connect-timeout 10 urlConnect timeout
curl -m 30 urlMax time
curl --max-time 30 urlMax time
curl --retry 3 urlRetry on failure
curl --retry-delay 5 urlDelay between retries

Output Control

Format and filter output.

CommandDescription
curl -s urlSilent (no progress)
curl -S urlShow errors in silent
curl -w "%{http_code}" urlPrint HTTP code
curl -w "%{time_total}" urlPrint total time
curl -o /dev/null -s -w "%{http_code}" urlStatus code only

Debug

Troubleshoot requests.

CommandDescription
curl -v urlVerbose
curl -vv urlMore verbose
curl --trace file urlFull trace to file
curl --trace-ascii file urlASCII trace
curl -D headers.txt urlDump headers

Common Patterns

Frequently used combinations.

CommandDescription
curl -sL urlSilent, follow redirects
curl -fsSL urlFail silently on errors
curl --json '{"key":"value"}' urlJSON POST
curl -u user:pass -XPUT -d @file urlAuth PUT from file