A Beginner's Guide to Using `curl` in Linux
curl?curl (short for "Client URL") is a command-line tool for transferring data using various network protocols. It’s pre-installed on most Linux distributions and is widely used for tasks like:
The simplest way to use curl is:
curl [options] [URL]To download a file from a URL:
curl -O https://example.com/file.zip-O saves the file with its original name.If you want to specify a different filename:
curl -o custom_name.zip https://example.com/file.zipcurl can send different types of HTTP requests.
curl https://api.example.com/datacurl -X POST -d "name=John&age=30" https://api.example.com/users-X POST specifies the HTTP method.-d sends data in the request body.curl -X POST -H "Content-Type: application/json" -d '{"name":"John","age":30}' https://api.example.com/users-H adds a header (like Content-Type).Some URLs redirect to another location. Use -L to follow them:
curl -L https://example.comIf a site requires a username and password:
curl -u username:password https://example.com/secureTo save cookies to a file:
curl -c cookies.txt https://example.comTo use saved cookies in a subsequent request:
curl -b cookies.txt https://example.com/dashboardIf you only want to see the response headers (not the body):
curl -I https://example.comTo avoid overloading a server (or your bandwidth), limit download speed:
curl --limit-rate 100K -O https://example.com/largefile.zip--limit-rate 100K restricts speed to 100 KB/s.curl is an essential tool for any Linux user working with web requests, APIs, or file downloads. Once you master the basics, you can automate tasks, debug APIs, and interact with remote servers efficiently.
Want to learn more? Check man curl for advanced options!
**Happy curling! **
Would you like me to add any specific examples or use cases? Let me know!