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.zipUse 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.comHeaders only (HEAD)
curl -v https://example.comVerbose: 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.urlFollow redirects
curl -# -O https://example.com/file.zip
curl -s https://jsonplaceholder.typicode.com/posts/1 | python3 -m json.tool
curl localhostthe page's HTML
curl -I localhostonly the response headers
curl localhost/about.html
curl -I localhost/missing.html404
curl -I localhost/secret.html403
curl -H 'Host: shop.local' localhostthe shop
curl shop.local
curl -s -o /dev/null -w '%{http_code}' http://shop.testJust the status code: 200
curl -s -o /dev/null -w '%{http_code}' http://api.test:8080/health000: nothing answered
curl -s http://app.test | grep '<p>'What do visitors see?
curl -I http://localhost
curl -s http://localhost | grep -i titleWhat does the server answer?
curl -I http://localhost/api/productsWhat does the API answer?
curl http://localhost/api/products
curl -I http://gallery.localThe answer, without the page
Lessons that use curl
- curl — HTTP from the Terminal
- nginx — Your First Web Server
- Serving Your Own Pages
- Configuration & Server Blocks
- Project: Uptime Monitor
- Project: Deploy with Rollback
- Mission: Service Down
- Mission: One Missing Character
- Mission: Port 80 Is Taken
- Mission: 502 Bad Gateway
- Mission: 403 Forbidden