Syntax Overview
cURL follows a straightforward invocation pattern:
curl [options] <URL>
Core Options Reference
| Option | Description |
|---|---|
-A, --user-agent |
Specifies client identification string |
-b, --cookie |
Sends cookies from string or file |
-c, --cookie-jar |
Persists cookies to file after transfer |
-C, --continue-at |
Resumes interrupted transfers |
-D, --dump-header |
Stores response headers to file |
-e, --referer |
Sets HTTP Referer header |
-f, --fail |
Returns error codes without server error pages |
-o, --output |
Writes content to specified filename |
-O, --remote-name |
Saves using the remote filename |
-r, --range |
Requests specific byte ranges |
-s, --silent |
Suppresses progress meters |
-T, --upload-file |
Transmits local files to server |
-u, --user |
Provides authentication credentials |
-w, --write-out |
Displays custom metrics after completion |
-x, --proxy |
Routes through specified proxy |
-#, --progress-bar |
Shows visual transfer progress |
Basic Resource Retrieval
Fetch a web page content:
curl https://api.example.org
This operation sends a GET request and streams the response body to stdout, useful for testing connectivity or viewing raw HTML.
Managing Output
Shell Redirection
Leverage Unix output redirection to capture content:
curl https://api.example.org >> response.html
Explicit File Naming
Use lowercase -o to define the destination filename explicitly:
curl -o response.html https://api.example.org
Preserving Remote Filenames
Uppercase -O retains the original server-side filename:
curl -O https://api.example.org/assets/image.jpg
Note that -O requires the URL to include a specific filename rather than a directory path.
Response Analysis
Extract HTTP status codes for debugging:
curl -o /dev/null -s -w "%{http_code}" https://api.example.org
This suppresses download progress and body output, returning only the numeric status code (200, 301, 404, etc.).
Proxy Configuration
Route traffic through intermediary servers:
curl -x proxy.example.com:8080 https://external-site.com
Cookie Management
Persisting Session Data
Store cookies for subsequent authenticated requests:
curl -c session.dat https://api.example.org/login
Capturing Response Headers
Save server headers including Set-Cookie directives:
curl -D headers.txt https://api.example.org
Note that -D captures the entire header block, while -c extarcts only cookie data.
Reusing Stored Sessions
Attach previously saved cookies to new requests:
curl -b session.dat https://api.example.org/dashboard
Request Customization
Client Identification
Masquerade as specific browser versions:
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
https://api.example.org
Referer Spoofing
Bypass hotlink protection mechanisms:
curl -e "https://trusted-domain.com" \
https://api.example.org/protected/image.jpg
File Transfer Operations
Sequential Batch Downloads
Download numbered sequences using bracket expansion:
curl -O https://api.example.org/docs/manual_[1-5].pdf
This retrieves manual_1.pdf through manual_5.pdf sequentially.
Partial Content Retrieval
Download large files in segments for parallel processing:
curl -r 0-1048576 -o part_aa.bin https://api.example.org/large-archive.zip
curl -r 1048577-2097152 -o part_ab.bin https://api.example.org/large-archive.zip
curl -r 2097153- -o part_ac.bin https://api.example.org/large-archive.zip
cat part_*.bin > complete-archive.zip
Transfer Progress Visualization
Enable hash-mark progress indicators:
curl -# -O https://api.example.org/distribution.tar.gz
Resuming Interrupted Transfers
Continue broken downloads automatically:
curl -C - -O https://api.example.org/distribution.tar.gz
The hyphen after -C instructs cURL to determine the resume point automatically.
Uploading Files
Transmit local files to remote servers:
curl -T report.csv -u username:secretkey ftp://ftp.example.org/incoming/