curl Command Guide
curl is a powerful command-line tool for transferring data with URLs. Learn how to make HTTP requests, download files, and interact with APIs.
8 min read•Last updated: January 19, 2025
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
curl URLFetch URL contentcurl -o file URLSave to filecurl -O URLSave with original nameHTTP Methods
-X POSTPOST request-X PUTPUT request-X DELETEDELETE requestData
-d "data"Send POST data-d @file.jsonSend file as data-F "file=@f.txt"Upload fileHeaders
-H "Key: Value"Add header-H "Content-Type: application/json"JSON content-u user:passBasic authOptions
-LFollow redirects-IHeaders only-vVerbose outputDownload
-C -Resume download--limit-rate 1MLimit speed-kInsecure (skip SSL)Downloadable Image Preview
Failed to generate preview
Basic Usage
curl fetches content from a URL and outputs it to stdout.
bash
curl https://example.comCommon Options
Frequently Used Options
| -o file | Save output to file |
| -O | Save with remote filename |
| -L | Follow redirects |
| -I | Fetch headers only |
| -v | Verbose output |
| -s | Silent mode |
| -X METHOD | Specify HTTP method |
| -H | Add custom header |
| -d | Send data in POST request |
Downloading Files
Save to specific file
bash
curl -o myfile.html https://example.com/page.htmlSave with original filename
bash
curl -O https://example.com/file.zipDownload multiple files
bash
curl -O https://example.com/file1.zip -O https://example.com/file2.zipResume interrupted download
bash
curl -C - -O https://example.com/largefile.zipFollow redirects
bash
curl -L -O https://example.com/downloadTip
Always use
-L to follow redirects, as many URLs redirect to the actual content.HTTP Methods
GET request (default)
bash
curl https://api.example.com/usersPOST request with data
bash
curl -X POST -d "name=John&email=john@example.com" https://api.example.com/usersPOST with JSON data
bash
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name": "John", "email": "john@example.com"}' \
https://api.example.com/usersPUT request
bash
curl -X PUT \
-H "Content-Type: application/json" \
-d '{"name": "Jane"}' \
https://api.example.com/users/1DELETE request
bash
curl -X DELETE https://api.example.com/users/1Headers and Authentication
Add custom headers
bash
curl -H "Authorization: Bearer token123" \
-H "Accept: application/json" \
https://api.example.com/dataBasic authentication
bash
curl -u username:password https://api.example.com/protectedView response headers
bash
# Headers only
curl -I https://example.com
# Headers and body
curl -i https://example.comWarning
Avoid putting sensitive credentials in command history. Use environment variables or config files for authentication tokens.
Working with APIs
Pretty print JSON (with jq)
bash
curl -s https://api.example.com/data | jq .Send JSON file as data
bash
curl -X POST \
-H "Content-Type: application/json" \
-d @data.json \
https://api.example.com/endpointUpload a file
bash
curl -X POST \
-F "file=@myfile.txt" \
https://api.example.com/uploadDebugging and Verbose Output
bash
# Verbose output showing request/response details
curl -v https://example.com
# Show only timing information
curl -w "Time: %{time_total}s\n" -o /dev/null -s https://example.com
# Show HTTP status code
curl -o /dev/null -s -w "%{http_code}\n" https://example.comPractical Examples
Check if a website is up
bash
curl -Is https://example.com | head -1Get your public IP
bash
curl ifconfig.meDownload a script and run it
bash
curl -fsSL https://example.com/install.sh | bashWarning
Be careful when piping scripts to bash. Always review the script first with
curl URL before executing.Test API with rate limiting
bash
curl --limit-rate 100K https://example.com/largefileUse a proxy
bash
curl -x http://proxy:8080 https://example.comIgnore SSL certificate errors
bash
curl -k https://self-signed.example.comSummary
curl is essential for HTTP requests and data transfer. Key takeaways:
- Use
-oor-Oto save downloads - Use
-Lto follow redirects - Use
-Xto specify HTTP method - Use
-Hfor custom headers - Use
-dto send POST data - Use
-vfor debugging
Official Documentation
For authoritative information, refer to the official documentation: