curl
is a command-line tool and library for transferring data with URLs. It’s widely used by developers, sysadmins, and automation scripts for making HTTP requests, testing APIs, downloading files, and more. This article guides you through installing curl
and demonstrates practical usage, including downloading files, inspecting HTTP headers, SSL verification, sending POST requests, and piping responses into jq
.
Installation
Linux
On Linux systems, you can install curl
using your package manager. For example, on Ubuntu or Debian-based systems:
1
2
sudo apt-get update
sudo apt-get install curl
On CentOS or RHEL-based systems:
1
sudo yum install curl
macOS
On macOS, you can install curl
using Homebrew:
1
brew install curl
Windows
On Windows, you can install curl
using Chocolatey:
1
choco install curl
User Guide
1. Downloading Files
To download a file from a URL, use the -o
option:
1
curl -o file.zip https://example.com/file.zip
2. Inspecting HTTP Headers
To view the HTTP headers of a URL, use the -I
option:
1
curl -I https://example.com
3. SSL Verification
To verify the SSL certificate of a URL, use the -vI
option:
1
2
3
4
curl -vI https://example.com
# You will see the SSL certificate information.
# You will see this line in the output if certificate is valid.
# SSL certificate verify ok.
4. Sending POST Requests
To send a POST request with data, use the -d
for data and -H
for Headers option:
1
2
3
curl -X POST -H "Content-Type: application/json" \
-d '{"name":"User","email":"user@example.com"}' \
https://example.com/api/users
5. Piping Responses into jq
To pipe the response into jq
, use the -s
option:
1
2
3
4
curl -s ipinfo.io | jq -r '.ip'
# This will print the IP address of the server.
curl -s ipinfo.io | jq -r '.ip' | xargs echo "IP Address: "
# This will print the IP address of the server with customize output format.
6. Piping Response to Shell
To pipe the response into a shell command, use the -s
option:
1
2
3
curl -s https://your-script-url/script.sh | bash
# This will directly execute the script.
# Note: Don't do it unless you trust the source.
Bonus Tips
Don’t forget to check man page of curl for more options.
1
man curl
Additionally, you can visit online curl
man page through curl man page.