Curl Command
On this page
- What is Linux curl Command?
- curl Syntax
- Basic curl Examples
- HTTP Methods with curl
- Authentication with curl
- Working with Cookies
- File Uploads and Downloads
- Advanced Features
- Working with JSON APIs
- Testing and Development
- Common Use Cases
- Troubleshooting
- curl Command Manual / Help
- References
- Related Linux Commands
- Summary

What is Linux curl Command?
curl is a powerful command-line tool for transferring data from or to servers. It supports numerous protocols including HTTP, HTTPS, FTP, FTPS, SFTP, and many others. The name “curl” stands for “Client URL” and it’s designed to work without user interaction, making it perfect for scripts and automation. From the man page:
curl is a tool for transfering data from or to a server. It supports these protocols: DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET or TFTP. The command is designed to work without user interaction.
curl offers a comprehensive set of features including proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, and much more.
curl Syntax
curl [options] <url>Basic curl Examples
Simple GET Request
The most basic curl command performs a GET request to retrieve content from a URL:
curl https://httpbin.org/getDownload a File
Download a file and save it with its original name:
curl -O https://example.com/file.zipDownload a file and save it with a custom name:
curl -o myfile.zip https://example.com/file.zipDisplay Only Response Headers
View only the HTTP headers without the response body:
curl -I https://httpbin.org/getInclude Response Headers with Body
Display both headers and response body:
curl -i https://httpbin.org/getFollow Redirects
Automatically follow HTTP redirects:
curl -L https://bit.ly/shortened-urlHTTP Methods with curl
GET Request (Default)
curl https://httpbin.org/getPOST Request with Data
Send data in a POST request:
curl -X POST -d "name=John&age=30" https://httpbin.org/postSend JSON data:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"John","age":30}' \
https://httpbin.org/postPUT Request
curl -X PUT \
-H "Content-Type: application/json" \
-d '{"name":"Jane","age":25}' \
https://httpbin.org/postDELETE Request
curl -X DELETE https://httpbin.org/deletePATCH Request
curl -X PATCH \
-H "Content-Type: application/json" \
-d '{"age":31}' \
https://httpbin.org/patchSet Custom Headers
curl -H "User-Agent: MyApp/1.0" \
-H "Accept: application/json" \
https://httpbin.org/headersMultiple Headers
curl -H "Authorization: Bearer token123" \
-H "Content-Type: application/json" \
-H "X-Custom-Header: value" \
https://api.example.com/dataAuthentication with curl
Basic Authentication
curl -u username:password https://api.example.com/resourceBearer Token Authentication
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/resourceAPI Key Authentication
curl -H "X-API-Key: YOUR_API_KEY" https://api.example.com/resourceWorking with Cookies
Save Cookies to File
curl -c cookies.txt https://example.com/loginSend Cookies from File
curl -b cookies.txt https://example.com/dashboardSet Cookie Manually
curl -b "session=abc123; theme=dark" https://example.com/pageFile Uploads and Downloads
Upload a File
curl -F "file=@/path/to/your/file.txt" https://httpbin.org/postDownload a File (Resuming)
curl -C - -O https://example.com/large-file.zipAdvanced Features
Using Proxy
curl --proxy http://proxy-server:8080 https://example.comIgnore SSL Certificate Errors
curl -k https://self-signed.badssl.com/Set Maximum Time for Request
curl --max-time 30 https://slow-server.comRetry Failed Requests
curl --retry 3 --retry-delay 2 https://unreliable-server.comVerbose Output for Debugging
curl -v https://httpbin.org/getSilent Mode (No Progress Bar)
curl -s https://api.example.com/dataRate Limiting
curl --limit-rate 100k -O https://example.com/largefile.zipWorking with JSON APIs
GET JSON Data
curl -H "Accept: application/json" https://jsonplaceholder.typicode.com/posts/1POST JSON Data
curl -X POST \
-H "Content-Type: application/json" \
-d '{ "title": "My Post", "body": "This is the post content", "userId": 1 }' \
https://jsonplaceholder.typicode.com/postsPretty Print JSON Response
curl -s https://api.github.com/users/octocat | python -m json.toolTesting and Development
Check Website Response Time
curl -w "@curl-format.txt" -o /dev/null -s https://example.comCreate curl-format.txt:
time_namelookup: %{time_namelookup}
time_connect: %{time_connect}
time_appconnect: %{time_appconnect}
time_pretransfer: %{time_pretransfer}
time_redirect: %{time_redirect}
time_starttransfer: %{time_starttransfer}
----------
time_total: %{time_total}Check HTTP Status Code Only
curl -o /dev/null -s -w "%{\nhttp_code}" https://example.comSave Response to Variable (in scripts)
response=$(curl -s https://api.example.com/status)
echo "API Status: $response"Common Use Cases
Health Check Endpoint
curl -f https://api.example.com/health || echo "Service is down"Download and Extract Archive
curl -L https://github.com/user/repo/archive/main.tar.gz | tar -xzSend Slack Notification
curl -X POST \
-H "Content-Type: application/json" \
-d '{"text":"Deployment completed successfully!"}' \
https://hooks.slack.com/services/YOUR/WEBHOOK/URLWeather API Example
curl -s "https://wttr.in/London?format=3"Troubleshooting
Common Error Messages
“Connection refused”
- The server is not running or not accessible
- Check the URL and port number
“SSL certificate problem”
- Use
-kto ignore SSL errors (not recommended for production) - Or fix the certificate issue
“HTTP 404 Not Found”
- Check the URL path
- Verify the endpoint exists
“HTTP 401 Unauthorized”
- Check authentication credentials
- Verify API key or token
Debugging Tips
- Use
-vfor verbose output to see full request/response details - Use
-Ito check headers without downloading content - Use
--trace-ascii trace.txtfor detailed debugging information - Check connectivity with a simple GET request first
Best Practices
- Always validate SSL certificates in production - avoid using
-k - Set appropriate timeouts - use
--max-timeto prevent hanging requests - Handle errors properly in scripts - check exit codes and use
-ffor failure detection - Use proper headers - set
Content-Type,User-Agent, etc. - Implement retry logic - use
--retryfor unreliable networks - Store sensitive data securely - avoid putting passwords/tokens directly in commands
curl Command Manual / Help
We can use man and info command to see the manual page of curl command. curl command also have --help option to show list of options. To open man page for curl command we can use command below. To exit man or info page you can press q.
man curlTo open info page for curl command we can use command below.
info curlTo open help page from curl command we can run command below.
curl --helpReferences
You can find more information about curl from the following links:
Related Linux Commands
You can read tutorials of related Linux commands below:
Summary
In this comprehensive tutorial, we’ve covered the essential aspects of using curl, from basic GET requests to advanced features like authentication, file uploads, and debugging. curl is an invaluable tool for web developers, system administrators, and anyone working with APIs or web services.
Key takeaways:
- curl supports numerous protocols and HTTP methods
- Authentication can be handled through various methods (Basic, Bearer tokens, API keys)
- File uploads and downloads are straightforward with the right options
- Debugging features help troubleshoot connection and request issues
- Best practices ensure secure and reliable usage
Visit our Linux Commands guide to learn more about using command line interface in Linux.