LinuxCommandLibrary

curl

TLDR

Download file

$ curl -O [https://example.com/file.zip]
copy
Save to specific file
$ curl -o [filename] [https://example.com/file]
copy
POST data
$ curl -X POST -d ["key=value"] [https://api.example.com]
copy
Follow redirects
$ curl -L [https://example.com]
copy
Send JSON
$ curl -H ["Content-Type: application/json"] -d ['{"key":"value"}'] [https://api.example.com]
copy
Show headers
$ curl -I [https://example.com]
copy

SYNOPSIS

curl [options] [URL...]

DESCRIPTION

curl is a command-line tool for transferring data with URLs. It supports HTTP, HTTPS, FTP, and many other protocols, making it essential for web development, API testing, and file transfers.
The tool is ubiquitous in scripts, CI/CD pipelines, and system administration.

PARAMETERS

-O, --remote-name

Save with remote filename
-o, --output file
Save to specified file
-L, --location
Follow redirects
-X, --request method
HTTP method (GET, POST, PUT, DELETE)
-d, --data data
Send POST data
-H, --header header
Add custom header
-u, --user user:pass
Authentication
-I, --head
Fetch headers only
-v, --verbose
Verbose output
-s, --silent
Silent mode
-f, --fail
Fail silently on HTTP errors
-k, --insecure
Allow insecure SSL connections

COMMON USES

Download file:

$ curl -O https://example.com/file.zip
curl -o myfile.zip https://example.com/download
copy
API calls:
$ # GET request
curl https://api.example.com/users

# POST JSON
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"name":"John","age":30}' \
  https://api.example.com/users

# With authentication
curl -u username:password https://api.example.com/data
copy
Headers:
$ # View response headers
curl -I https://example.com

# Custom headers
curl -H "Authorization: Bearer TOKEN" \
  https://api.example.com/secure
copy

FEATURES

- Multiple protocols (HTTP, HTTPS, FTP, SFTP, etc.)
- Authentication (Basic, Digest, OAuth, etc.)
- Cookie support
- Proxy support
- SSL/TLS
- Rate limiting
- Resume transfers
- Multiple simultaneous transfers

CAVEATS

Silent failures by default (use -f to change). Large downloads show progress by default (use -s for scripts). Cookie files need management. SSL certificate issues require -k (insecure). Complex syntax for advanced features.

HISTORY

curl was created by Daniel Stenberg in 1997 (originally httpget), becoming one of the most widely used command-line tools for data transfer.

SEE ALSO

wget(1), http(1), fetch(1)

Copied to clipboard