You’ve undoubtedly heard of curl, as it’s one of the most popular HTTP utilities used on Linux and other unix-based systems. You may not know that it is able to transfer data for a rather generous list of protocols (you can find the whole list at the cURL website). It’s also a widely used library in software applications, but today we’re going to stick to the command line utility.

Below are a list of cURL showing common use cases you’ll encounter. I’ve preferred to use the long-style argument names as I feel they’re easier to remember.

One note, you’ll see a lot of examples for POST that involve using a flag like -X POST. As also noted in the official cURL man page, this only changes the method name in the request, it does not change cURL’s behavior. You’re usually better-off using options like --data to POST, and --head to make HEAD requests, as -X,--request can provide unexpected results:

This option only changes the actual word used in the HTTP request, it does not alter the way curl behaves. So for example if you want to make a proper HEAD request, using -X HEAD will not suffice. You need to use the -I, –head option.

The method string you set with -X, –request will be used for all requests, which if you for example use -L, –location may cause unintended side-effects when curl doesn’t change request method according to the HTTP 30x response codes - and similar.

GET Examples

show response body:


show response headers and body:

curl --include

show only response headers:

curl --head

don’t show progress meter or errors:

curl --silent

follow redirects:

curl --location

skip SSL certificate verification:

curl --insecure

use a specific network interface:

curl --interface eth0

force IPv4:

curl --ipv4

force IPv6:

curl --ipv6

basic authentication:

curl --user=michael:password123

save response to a file of the same name (like wget):

curl -O

save response to a specified filename:

curl -o new_name.txt

send URL-encoded key/value pair options in the URL:

curl --get --data-urlencode key0=value0 --data-urlencode key1=value1

POST Examples

JSON payload with custom headers:

curl --header "Content-type: application/json" --data '{"key":"value"}'

load JSON payload from a file:

curl --header "Content-type: application/json" --data @/home/michael/json.txt

URL-encoded key/value pair options:

curl --data-urlencode key0=value0 --data-urlencode key1=value1