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:

CommandDescription
curl [URL]Make a GET request.
curl -o [output_file] [URL]Save output to a file.

HTTP Methods:

CommandDescription
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:

CommandDescription
curl -H "Header: Value" [URL]Include headers in the request.

Follow Redirects:

CommandDescription
curl -L [URL]Follow redirects.

Authentication:

CommandDescription
curl -u username:password [URL]Basic authentication.

Upload Files:

CommandDescription
curl -X POST -F "file=@/path" [URL]Upload a file with POST.

Download Resume:

CommandDescription
curl -C - -O [URL]Resume download.

Show Request and Response Details:

CommandDescription
curl -v [URL]Verbose mode, show details.

Output to Dev Null:

CommandDescription
curl -s -o /dev/null [URL]Suppress progress and output.

User Agent:

CommandDescription
curl -A "UserAgentString" [URL]Set User Agent.

Timeouts:

CommandDescription
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.