Curl (Client for URLs) is a versatile command-line tool for making HTTP requests. It supports various protocols and is widely used for testing APIs, downloading files, and more.
Basic Usage:
Command
Description
curl [URL]
Make a GET request.
curl -o [output_file] [URL]
Save output to a file.
HTTP Methods:
Command
Description
curl -X POST -d "data" [URL]
Make a POST request with data.
curl -X PUT -d "data" [URL]
Make a PUT request with data.
curl -X DELETE [URL]
Make a DELETE request.
Headers:
Command
Description
curl -H "Header: Value" [URL]
Include headers in the request.
Follow Redirects:
Command
Description
curl -L [URL]
Follow redirects.
Authentication:
Command
Description
curl -u username:password [URL]
Basic authentication.
Upload Files:
Command
Description
curl -X POST -F "file=@/path" [URL]
Upload a file with POST.
Download Resume:
Command
Description
curl -C - -O [URL]
Resume download.
Show Request and Response Details:
Command
Description
curl -v [URL]
Verbose mode, show details.
Output to Dev Null:
Command
Description
curl -s -o /dev/null [URL]
Suppress progress and output.
User Agent:
Command
Description
curl -A "UserAgentString" [URL]
Set User Agent.
Timeouts:
Command
Description
curl --connect-timeout 10 [URL]
Set connection timeout.
Bonus Tips:
To install curl on Debian-based systems:
sudo apt-get install curl
To install curl on Red Hat-based systems:
sudo yum install curl
Conclusion
This curl cheat sheet provides a concise reference for a variety of HTTP request scenarios. Use these commands to interact with APIs and services effectively, and enhance your command-line capabilities for web interactions.