curl Basics
Bash
# GET request
curl https://api.example.com/users
# Pretty-print the response (paired with jq)
curl -s https://api.github.com/users/octocat | jq '.'
# Status code only
curl -o /dev/null -s -w "%{http_code}" https://example.com
# Verbose output (including headers)
curl -v https://example.com
# Headers only
curl -I https://example.com
# Follow redirects
curl -L https://example.com
# Timeouts
curl --connect-timeout 5 --max-time 30 https://example.comHTTP Methods and Headers
Bash
# POST — JSON body
curl -X POST https://api.example.com/users -H "Content-Type: application/json" -d '{"name":"Alice","email":"alice@example.com"}'
# PUT
curl -X PUT https://api.example.com/users/1 -H "Content-Type: application/json" -d '{"name":"Alice Updated"}'
# DELETE
curl -X DELETE https://api.example.com/users/1
# PATCH
curl -X PATCH https://api.example.com/users/1 -H "Content-Type: application/json" -d '{"email":"new@example.com"}'
# Multiple headers
curl https://api.example.com -H "Accept: application/json" -H "X-Request-ID: abc123" -H "User-Agent: MyScript/1.0"Authentication
Bash
# Bearer token
curl -H "Authorization: Bearer eyJhbGci..." https://api.example.com/me
# Basic Auth
curl -u username:password https://api.example.com
# or
curl -H "Authorization: Basic $(echo -n user:pass | base64)" https://api.example.com
# API key
curl -H "X-API-Key: your-api-key" https://api.example.com
# Cookies
curl -b "session=abc123; token=xyz" https://example.com
# Save and send cookies
curl -c cookies.txt https://example.com/login -d "user=admin&pass=1234"
curl -b cookies.txt https://example.com/dashboardFile Upload
Bash
# Form file upload (multipart)
curl -F "file=@/path/to/file.pdf" https://api.example.com/upload
curl -F "file=@image.jpg;type=image/jpeg" -F "name=profile" https://example.com
# Raw binary data
curl -X PUT --data-binary @file.tar.gz https://example.com/uploadFile Download
Bash
# Save file (-O: original filename, -o: specified filename)
curl -O https://example.com/file.tar.gz
curl -o myfile.tar.gz https://example.com/file.tar.gz
# Show progress
curl -# -O https://example.com/large-file.iso
# Resume (interrupted download)
curl -C - -O https://example.com/large-file.iso
# Parallel downloads (with xargs)
cat urls.txt | xargs -n1 -P4 curl -Owget Basics
Bash
# Download a file
wget https://example.com/file.tar.gz
# Resume download
wget -c https://example.com/large-file.iso
# Quiet (no progress)
wget -q https://example.com/file.tar.gz
# Number of retries
wget --tries=5 https://example.com/file.tar.gz
# Save under a specific filename
wget -O myfile.tar.gz https://example.com/file
# Recursive download (site mirroring)
wget -r -np -nH --cut-dirs=1 https://example.com/docs/
# Specific file types only
wget -r -A "*.pdf" https://example.com/papers/When to Choose curl vs wget
| Situation | Recommended |
|---|---|
| REST API testing | curl |
| Custom HTTP methods/headers | curl |
| File download (resume) | wget |
| Site mirroring | wget |
| API calls in scripts | curl |
| FTP file download | curl |
Editorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Questions & answers
Ask a question about this guide. We'll review and reply.