Quick Reference

Cheatsheets

Practical command references for Linux, networking, servers, containers, databases, and more.

Cheatsheet#curl-cheatsheet

cURL Cheatsheet

curl (Client URL) is a command-line tool for transferring data using various network protocols, most commonly HTTP/HTTPS.

Basic HTTP Requests

# GET request (Fetch a webpage)
curl https://example.com
 
# GET request and save output to a file (-o)
curl -o file.html https://example.com
 
# GET request and save output using original filename (-O)
curl -O https://example.com/file.zip
 
# Follow redirects (-L)
curl -L https://example.com

Headers and Data

# Send a POST request (-X)
curl -X POST https://example.com/api/users
 
# Send custom Headers (-H)
curl -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     https://api.example.com/data
 
# Send JSON Data (-d)
curl -X POST https://api.example.com/users \
     -H "Content-Type: application/json" \
     -d '{"name": "John", "age": 30}'
 
# Send Data from a file
curl -X POST https://api.example.com/users \
     -H "Content-Type: application/json" \
     -d @data.json

Authentication

# Basic Authentication (-u)
curl -u username:password https://example.com/protected
 
# Prompt for password instead of hardcoding
curl -u username https://example.com/protected

Debugging and Information

# Print verbose output (shows request and response headers) (-v)
curl -v https://example.com
 
# Fetch headers only (HEAD request) (-I)
curl -I https://example.com
 
# Print only the HTTP status code
curl -s -o /dev/null -w "%{http_code}" https://example.com
 
# Silent mode (hide progress meter or error messages) (-s)
curl -s https://example.com

Downloading and Resuming

# Resume an interrupted download (-C -)
curl -C - -O https://example.com/largefile.zip
 
# Limit download rate (e.g., to 1 Megabyte per second)
curl --limit-rate 1M -O https://example.com/largefile.zip