$linuxjunkies
>

curl(1)

Transfer data from or to a server using URLs, supporting HTTP, HTTPS, FTP, and many other protocols.

UbuntuDebianFedoraArch

Synopsis

curl [OPTION]... [URL]...

Description

curl is a command-line tool for transferring data using URLs. It supports a wide range of protocols including HTTP, HTTPS, FTP, SFTP, LDAP, and more. curl is commonly used for downloading files, testing APIs, submitting forms, and automating web requests in scripts.

By default, curl sends a GET request and outputs the response to stdout. Headers and response data are sent together unless separated with specific flags. curl can handle redirects, cookies, authentication, proxies, and custom headers.

Common options

FlagWhat it does
-o FILEWrite output to FILE instead of stdout
-OSave output to a file named after the remote file
-X METHODSpecify HTTP request method (GET, POST, PUT, DELETE, etc.)
-H HEADERAdd custom header; use multiple times for multiple headers
-d DATASend DATA in POST request body; implies -X POST
-LFollow HTTP redirects (3xx responses)
-u USER:PASSUse basic authentication with username and password
-A AGENTSet User-Agent header
-b COOKIESend cookies or read from file
-iInclude HTTP headers in output
-IFetch headers only (HEAD request)
-vVerbose; show request and response details

Examples

Fetch and display a webpage

curl https://example.com

Download a file and save it as myfile.html

curl -o myfile.html https://example.com

Send a JSON POST request to an API endpoint

curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/endpoint

Access a page requiring basic authentication

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

Follow redirects automatically

curl -L https://example.com/redirect

Display response headers along with the body

curl -i https://example.com

Fetch only HTTP headers (useful for checking status codes)

curl -I https://example.com

Use cookies from a file and save new cookies to it

curl -b cookies.txt -c cookies.txt https://example.com

Related commands