curl Command
Beginner Networking man(1)Transfer data from or to a server using various protocols
👁 10 views
📅 Updated: Mar 15, 2026
SYNTAX
curl [OPTION]... [URL]
What Does curl Do?
curl is a command-line tool for transferring data using various protocols including HTTP, HTTPS, FTP, SCP, and more. It is the most versatile data transfer tool in Linux, used for API testing, file downloading, web scraping, and automation.
curl supports HTTP methods (GET, POST, PUT, DELETE), custom headers, authentication, cookies, proxies, SSL/TLS, file uploads, and form submissions. It can follow redirects, handle compressed responses, and show detailed connection information.
curl is essential for developers, system administrators, and DevOps engineers. It is used daily for testing REST APIs, downloading files, monitoring services, webhooks, and automating HTTP-based workflows.
curl supports HTTP methods (GET, POST, PUT, DELETE), custom headers, authentication, cookies, proxies, SSL/TLS, file uploads, and form submissions. It can follow redirects, handle compressed responses, and show detailed connection information.
curl is essential for developers, system administrators, and DevOps engineers. It is used daily for testing REST APIs, downloading files, monitoring services, webhooks, and automating HTTP-based workflows.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -o | Write output to file | curl -o file.zip https://example.com/file.zip |
| -O | Save with remote filename | curl -O https://example.com/archive.tar.gz |
| -X | Specify HTTP method | curl -X POST https://api.example.com/data |
| -H | Add custom header | curl -H 'Authorization: Bearer token123' https://api.example.com |
| -d | Send POST data | curl -X POST -d '{"name":"test"}' -H 'Content-Type: application/json' https://api.example.com |
| -I | Show response headers only (HEAD request) | curl -I https://example.com |
| -L | Follow redirects | curl -L https://shortened.url/abc |
| -s | Silent mode (no progress bar) | curl -s https://api.example.com/health |
| -v | Verbose — show request/response details | curl -v https://example.com |
| -k | Skip SSL certificate verification | curl -k https://self-signed.example.com |
| -u | Provide authentication credentials | curl -u user:pass https://api.example.com |
Practical Examples
#1 GET request
Makes a simple GET request and displays the response body.
$ curl https://api.example.com/users#2 POST JSON data
Sends a JSON payload via POST request.
$ curl -X POST -H 'Content-Type: application/json' -d '{"name":"John","email":"john@example.com"}' https://api.example.com/users#3 Download a file
Downloads a file following redirects, saving with the remote filename.
$ curl -O -L https://github.com/user/repo/archive/main.tar.gz#4 Check HTTP status
Returns only the HTTP status code — perfect for monitoring scripts.
$ curl -s -o /dev/null -w "%{http_code}" https://example.com
Output:
200
#5 Send form data
Uploads a file as multipart form data.
$ curl -X POST -F 'file=@report.pdf' -F 'name=Report' https://upload.example.com#6 View response headers
Shows only the response headers (HEAD request).
$ curl -I https://example.com
Output:
HTTP/2 200
content-type: text/html
server: nginx
#7 API with authentication
Makes an authenticated API request with a Bearer token.
$ curl -H 'Authorization: Bearer eyJhbG...' https://api.example.com/me#8 Test with verbose output
Shows full connection details including TLS handshake, headers sent/received.
$ curl -v https://example.com 2>&1Tips & Best Practices
Pretty-print JSON: Pipe JSON responses through jq for readable output: curl -s https://api.example.com/data | jq .
curl vs wget: curl is better for API testing, custom headers, and protocols. wget is better for recursive downloads and mirroring. curl outputs to stdout by default; wget saves to files.
Security with -k: Never use -k (skip SSL verification) in production scripts. It disables certificate checking and makes the connection vulnerable to man-in-the-middle attacks.
Frequently Asked Questions
How do I make a POST request?
Use curl -X POST -d 'data' URL. For JSON: curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' URL.
How do I download a file?
Use curl -O URL to save with the remote filename, or curl -o myfile.zip URL to specify a local filename. Add -L to follow redirects.
How do I check if a URL is reachable?
Use curl -s -o /dev/null -w "%{http_code}" URL. This silently makes the request and returns only the HTTP status code.
Related Commands
More Networking Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →