Curl Cheatsheet
#
curl
is a command-line tool used for transferring data with URLs. It supports various protocols and options.
Basic Commands
#
Command/Option | Example | Description |
---|
curl <url> | curl http://example.com | Fetch the content of the URL |
curl -O <url> | curl -O http://example.com/file.txt | Download the file from the URL |
curl -o <file> <url> | curl -o myfile.txt http://example.com/file.txt | Save the content to a file |
curl -I <url> | curl -I http://example.com | Fetch only the HTTP headers from the URL |
Request Methods
#
Command/Option | Example | Description |
---|
curl -X GET <url> | curl -X GET http://example.com | Perform a GET request (default method) |
curl -X POST <url> | curl -X POST http://example.com | Perform a POST request |
curl -X PUT <url> | curl -X PUT http://example.com | Perform a PUT request |
curl -X DELETE <url> | curl -X DELETE http://example.com | Perform a DELETE request |
Data Sending
#
Command/Option | Example | Description |
---|
curl -d <data> <url> | curl -d "name=value" http://example.com | Send data in a POST request |
curl -d @<file> <url> | curl -d @data.json http://example.com | Send data from a file in a POST request |
curl -F <name=@file> <url> | curl -F "file=@upload.txt" http://example.com | Upload a file |
Authentication
#
Command/Option | Example | Description |
---|
curl -u <user:password> <url> | curl -u user:pass http://example.com | Use HTTP basic authentication |
curl -H "Authorization: Bearer <token>" <url> | curl -H "Authorization: Bearer my_token" http://example.com | Use Bearer token for authentication |
Handling Output
#
Command/Option | Example | Description |
---|
curl -s <url> | curl -s http://example.com | Silent mode, no progress meter or error messages |
curl -S <url> | curl -S http://example.com | Show errors in silent mode |
curl -L <url> | curl -L http://example.com | Follow redirects |
Additional Options
#
Command/Option | Example | Description |
---|
curl -v <url> | curl -v http://example.com | Verbose mode, show detailed information |
curl --retry <num> | curl --retry 3 http://example.com | Retry request on failure |
Troubleshooting
#
Command/Option | Example | Description |
---|
curl --trace <file> <url> | curl --trace /tmp/trace.txt http://example.com | Trace the request and response to a file |
This cheatsheet provides fundamental curl
commands and options for transferring data with URLs.