curl Command

The curl command transfers data from or to servers using various protocols including HTTP, HTTPS, FTP, and more. It's a powerful tool for downloading files, making API calls, and testing web services.

Syntax

curl [OPTIONS] [URL...]

Description

The curl command is a versatile tool for transferring data with servers. It supports numerous protocols and can be used for various tasks from simple file downloads to complex API interactions.

Key features:

  • Supports HTTP, HTTPS, FTP, FTPS, and many other protocols
  • Can send various types of HTTP requests (GET, POST, PUT, DELETE, etc.)
  • Handles cookies, authentication, and headers
  • Supports file uploads and downloads
  • Can follow redirects and handle SSL certificates

Common Options

Option Description
-o, --output Write output to file instead of stdout
-O, --remote-name Save with remote filename
-X, --request Specify request method (GET, POST, etc.)
-H, --header Add custom header to request
-d, --data Send data in POST request
-u, --user Server user and password
-L, --location Follow redirects
-s, --silent Silent mode (no progress bar)
-v, --verbose Verbose output

Examples

Basic HTTP GET request

curl https://example.com

Fetches the content from the URL and displays it

Download file with original name

curl -O https://example.com/file.zip

Downloads the file and saves it as 'file.zip'

Download file with custom name

curl -o myfile.zip https://example.com/file.zip

Downloads the file and saves it as 'myfile.zip'

POST request with data

curl -X POST -d "name=John&age=30" https://api.example.com/users

Sends a POST request with form data

POST request with JSON data

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

Sends a POST request with JSON data

Add custom headers

curl -H "Authorization: Bearer token123" -H "User-Agent: MyApp/1.0" https://api.example.com/data

Includes custom headers in the request

Follow redirects

curl -L https://short.url/redirect

Follows HTTP redirects automatically

Basic authentication

curl -u username:password https://secure.example.com/data

Uses HTTP basic authentication

Upload file

curl -X POST -F "[email protected]" https://upload.example.com/

Uploads a file using multipart form data

Save response headers

curl -D headers.txt https://example.com

Saves response headers to a file

See also