Catalog / Curl Comprehensive Cheatsheet

Curl Comprehensive Cheatsheet

A comprehensive cheat sheet for Curl, covering essential commands, options, and examples for effective command-line data transfer. Includes authentication, request types, data handling, SSL, and more.

Basic Usage & Options

Basic Syntax

curl [options] [URL]

Basic curl command structure. Options modify the behavior, and URL specifies the target.

curl https://example.com

Simplest usage: retrieves the content of example.com and prints it to standard output.

Output and Verbosity

-o <file> or --output <file>

Saves the output to the specified file instead of printing to stdout.

Example:
curl -o downloaded.html https://example.com

-v or --verbose

Enables verbose mode, showing detailed information about the request process (headers, connection details, etc.).

Example:
curl -v https://example.com

-s or --silent

Silent mode. Doesn’t show progress meter or error messages. Useful for scripts.

Example:
curl -s https://example.com > /dev/null

-S or --show-error

When used with -s, shows error messages but suppresses the progress meter.

Example:
curl -sS https://example.com

Headers

-i or --include

Includes the HTTP headers in the output.

Example:
curl -i https://example.com

-I or --head

Performs a HEAD request, retrieving only the HTTP headers. Good for checking resource status.

Example:
curl -I https://example.com

-H "Header: Value" or --header "Header: Value"

Adds a custom header to the request.

Example:
curl -H "Content-Type: application/json" https://example.com

--compressed

Requests a compressed response using deflate or gzip.

Example:
curl --compressed https://example.com

Requests and Data Handling

Request Types

-X <command> or --request <command>

Specifies the HTTP request method (e.g., GET, POST, PUT, DELETE).

Example:
curl -X POST https://example.com

-L or --location

Follows HTTP redirects. Useful when a resource has moved.

Example:
curl -L https://example.com

-G or --get

Sends data with the HTTP GET method.

Example:
curl -G -d "param1=value1&param2=value2" https://example.com

Data Transfer

-d 'data' or --data 'data'

Sends HTTP POST data, URL-encoded.

Example:
curl -d "name=John&age=30" https://example.com

-d @file or --data @file

Sends data from a file as HTTP POST data.

Example:
curl -d @data.json https://example.com

-F <name=content> or --form <name=content>

Used for multipart/form-data, typically for file uploads.

Example:
curl -F "file=@my_image.jpg" https://example.com/upload
curl -F "data=some text" https://example.com

Authentication

-u <user:password> or --user <user:password>

Provides username and password for HTTP authentication.

Example:
curl -u user:password https://example.com

--basic

Use HTTP Basic Authentication (default when using -u).

Example:
curl --basic -u user:password https://example.com

--digest

Use HTTP Digest Authentication

Example:
curl --digest -u user:password https://example.com

SSL/TLS Options

Certificate Verification

--cacert <file>

Specifies the CA certificate file for verifying the server’s certificate.

Example:
curl --cacert ca.pem https://example.com

--capath <dir>

Specifies a directory containing CA certificates.

Example:
curl --capath /etc/ssl/certs https://example.com

-k or --insecure

Skips SSL certificate verification. Use with caution!

Example:
curl -k https://self-signed.example.com

Client Certificates

-E <cert> or --cert <cert>

Specifies the client certificate file.

Example:
curl --cert client.pem https://example.com

--cert-type <type>

Specifies the client certificate type (DER, PEM, ENG).

Example:
curl --cert client.pem --cert-type PEM https://example.com

–key

Private key file name (SSL)

Example:
curl --key private.key https://example.com

Other SSL Options

--ciphers <list>

SSL ciphers to use

Example:
curl --ciphers ECDHE-RSA-AES128-GCM-SHA256 https://example.com

--tlsv1.0, --tlsv1.1, --tlsv1.2, --tlsv1.3

Force curl to use specified TLS version.

Example:
curl --tlsv1.2 https://example.com

--ssl-allow-beast

Allow security flaws present in older SSL/TLS versions

Example:
curl --ssl-allow-beast https://example.com

Advanced Usage

Cookies

-b <name=value> or --cookie <name=value>

Sends a cookie with the request.

Example:
curl -b "sessionid=12345" https://example.com

-b <file> or --cookie <file>

Reads cookies from a file.

Example:
curl -b cookies.txt https://example.com

-c <file> or --cookie-jar <file>

Stores received cookies in a file.

Example:
curl -c cookies.txt https://example.com

User Agent

-A <string> or --user-agent <string>

Sets the User-Agent header.

Example:
curl -A "My Custom Agent" https://example.com

Error Handling

--fail

Fail silently (no output at all) on HTTP errors.

Example:
curl --fail https://example.com/nonexistent

--retry <num>

Retry request specified number of times if transient problems occur

Example:
curl --retry 3 https://example.com

--max-redirs <num>

Maximum number of redirects allowed

Example:
curl --max-redirs 5 https://example.com