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.

Installation

curl is pre-installed on most Linux distributions and macOS. If missing:

# Debian / Ubuntu
sudo apt install curl
 
# RHEL / CentOS / Fedora
sudo dnf install curl
 
# Arch Linux
sudo pacman -S curl

Basic HTTP Requests

# GET request (fetch a webpage)
curl https://example.com
 
# GET request and save output to a file
curl -o output.html https://example.com
 
# GET request and save using the remote filename
curl -O https://example.com/file.zip
 
# Follow redirects (3xx responses)
curl -L https://example.com
 
# Silent mode (hide progress bar and errors)
curl -s https://example.com

HTTP Methods

# GET (default)
curl https://api.example.com/users
 
# POST with JSON body
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "John", "age": 30}'
 
# PUT (full update)
curl -X PUT https://api.example.com/users/1 \
  -H "Content-Type: application/json" \
  -d '{"name": "John Updated", "age": 31}'
 
# PATCH (partial update)
curl -X PATCH https://api.example.com/users/1 \
  -H "Content-Type: application/json" \
  -d '{"age": 32}'
 
# DELETE
curl -X DELETE https://api.example.com/users/1

Headers

# Send custom headers
curl -H "Authorization: Bearer <token>" \
     -H "Accept: application/json" \
     https://api.example.com/data
 
# Send form data (application/x-www-form-urlencoded)
curl -X POST -d "username=admin&password=secret" https://example.com/login

Sending Data

# Send JSON from a file
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d @data.json
 
# Upload a file (multipart form data)
curl -X POST -F "file=@/path/to/photo.jpg" https://example.com/upload
 
# Upload multiple files
curl -X POST -F "[email protected]" -F "[email protected]" https://example.com/upload

Authentication

# Basic authentication (username:password)
curl -u username:password https://example.com/protected
 
# Prompt for password (avoids exposing it in shell history)
curl -u username https://example.com/protected
 
# Bearer token authentication
curl -H "Authorization: Bearer eyJhbGciOi..." https://api.example.com/me

Cookies

# Save cookies from a response to a file
curl -c cookies.txt https://example.com/login -d "user=admin&pass=secret"
 
# Send cookies from a file with a subsequent request
curl -b cookies.txt https://example.com/dashboard

Debugging and Information

# Verbose output (shows request/response headers and TLS handshake)
curl -v https://example.com
 
# Fetch response headers only (HEAD request)
curl -I https://example.com
 
# Print only the HTTP status code
curl -s -o /dev/null -w "%{http_code}" https://example.com
 
# Show response time
curl -s -o /dev/null -w "Time: %{time_total}s\n" https://example.com
 
# Write response headers to a file and body to another
curl -D headers.txt -o body.html https://example.com

Downloading

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

Proxy

# Use an HTTP proxy
curl -x http://proxy.example.com:8080 https://example.com
 
# Use a SOCKS5 proxy
curl --socks5 127.0.0.1:9090 https://example.com

SSL/TLS

# Skip SSL certificate verification (insecure — for testing only)
curl -k https://self-signed.example.com
 
# Use a custom CA certificate
curl --cacert /path/to/ca.crt https://example.com
 
# Use client certificate authentication
curl --cert client.crt --key client.key https://api.example.com