cURL is a well-known utility for transferring data using various protocols, most notably HTTP(S). cURL offers hundreds of CLI parameters. It would be impossible to test or even remember each of them. In this article, you will find some CLI parameters that you may find quite useful in DevOps.

Basics Link to heading

--connect-timeout Link to heading

Sets the connection timeout to defined number of seconds.

curl --connect-timeout 20 https://example.com

-L, --location Link to heading

Directs curl to follow redirect given by 3XX HTTP response code.

curl -L https://example.com

-o, --output <file> Link to heading

Writes output to specified file. Variables can be used if downloading multiple files:

curl "http://{one,two}.example.com" -o "file_#1.txt"

You can also suppress the output:

curl example.com -o /dev/null

And finally, you can also use it multiple times in one command:

curl -o file https://example.com -o file2 https://example.net

-A, --user-agent <name> Link to heading

Specifies the User-Agent that is sent with the request.

curl -A "Mozilla/5.0" https://example.com

-s, --silent Link to heading

Silent mode - curl will output nothing (but still download the data - redirection using --output is advised).

--rate-limit <limit> Link to heading

Limit transfer rate (download and upload) to defined limit. Limit is given as bytes per second. The number has to be followed by a suffix, one from (k, M, G, T, P). Every suffix is 1024 based.

curl --limit-rate 100K https://example.com
curl --limit-rate 10M https://example.com

-#, --progress-bar Link to heading

Show simple transfer progress bar (made of the # characters) instead of the default meter.

curl -# -O https://example.com

--keepalive or --no-keepalive Link to heading

Disable or enable keepalive.

curl --no-keepalive https://example.com
curl --keepalive https://example.com

DNS Link to heading

--dns-servers <addresses> Link to heading

Specify list of DNS servers (separated with commas if needed) to resolve the domain name with.

Note: this probably won’t work on Debian based system (it still does not work in Ubuntu 22.04). In this case, you have to resolve the domain manually (using dig) and pass its address to curl using the --resolve parameter.

--ipv4 and --ipv6 Link to heading

Resolve names using only IPv4 or IPv6

curl --ipv4 https://example.com
curl --ipv6 https://example.com

TLS & Certificates Link to heading

-k, --insecure Link to heading

Disable certificate verification. Useful for self-signed certificates or if you want to accept an expired certificate.

curl --insecure https://example.com

--cacert <file> and --capath <path> Link to heading

Specifies file or folder containing PEM-formatted certificate(s) to verify the peer. --cacert can be used only once.

Example:

curl --cacert CA-file.txt https://example.com
curl --capath /local/directory https://example.com

--crlfile <file> Link to heading

This gives curl the Certificate revocation list in PEM format - curl will check against this list if the peer’s certificate was revoked or not.

curl --crlfile rejects.txt https://example.com

--ssl-no-revoke Link to heading

Disables certificate revocation checks.

--tls-max <VERSION> Link to heading

Specifies maximum supported TLS version. The minimum version is specified by one of the following parameters: --tlsv1.0, --tlsv1.1, --tlsv1.2, --tlsv1.3

curl --tls-max 1.2 https://example.com
curl --tls-max 1.3 --tlsv1.2 https://example.com

Headers Link to heading

-i, --include Link to heading

Print HTTP response headers at the beginning of the output (before the content)

curl -i https://example.com

--dump-header <filename> Link to heading

Write received headers to a file.

curl --dump-header store.txt https://example.com

-H, --header Link to heading

Submit specified header with the request. Can be used multiple times to define more headers.

curl -H "X-First-Name: Joe" https://example.com

HTTP Methods and Protocols Link to heading

-X, --request <method> Link to heading

You can use --request parameter to specify request method. You can also use specific parameter for each method directly:

-G, --get
-I, --head

You can specify which HTTP protocol version should curl prefer to make the connection.

--http0.9
--http1.0
--http1.1
--http2
--http3

Further study Link to heading

You can always study all parameters in man pages:

man curl