The curl command

transfer a URL 29 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-I, --head
(HTTP FTP FILE) Fetch the headers only. HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document.
-s, --silent
Silent or quiet mode. Do not show progress meter or error messages.
-H, --header <header/@file>
(HTTP IMAP SMTP) Extra header to include in information sent.
-o, --output <file>
Write output to the given file instead of stdout.
-O, --remote-name
Write output to a local file named like the remote file we get.
-w, --write-out <format>
Make curl display information on stdout after a completed transfer.
-X, --request <method>
Change the method to use when starting the transfer.
-d, --data <data>
(HTTP MQTT) Send the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an…
-L, --location
(HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX…
-u, --user <user:password>
Specify the username and password to use for server authentication.
-v, --verbose
Make curl output verbose information during the operation.

Examples

curl https://httpbin.org/get
curl -s https://api.ipify.org

-s = silent (no progress)

curl -o output.html https://example.com
curl -O https://example.com/file.zip

Use remote filename

curl -X POST -d 'name=IVski&email=test@test.com' https://httpbin.org/post
curl -X POST -H 'Content-Type: application/json' \
curl -I https://example.com

Headers only (HEAD)

curl -v https://example.com

Verbose: all headers

curl -H 'Authorization: Bearer TOKEN' URL
curl -H 'User-Agent: MyBot/1.0' URL
curl -u username:password https://api.example.com
curl -L https://short.url

Follow redirects

curl -# -O https://example.com/file.zip
curl -s https://jsonplaceholder.typicode.com/posts/1 | python3 -m json.tool
curl localhost

the page's HTML

curl -I localhost

only the response headers

curl localhost/about.html
curl -I localhost/missing.html

404

curl -I localhost/secret.html

403

curl -H 'Host: shop.local' localhost

the shop

curl shop.local
curl -s -o /dev/null -w '%{http_code}' http://shop.test

Just the status code: 200

curl -s -o /dev/null -w '%{http_code}' http://api.test:8080/health

000: nothing answered

curl -s http://app.test | grep '<p>'

What do visitors see?

curl -I http://localhost
curl -s http://localhost | grep -i title

What does the server answer?

curl -I http://localhost/api/products

What does the API answer?

curl http://localhost/api/products
curl -I http://gallery.local

The answer, without the page

Lessons that use curl

Related commands