curl

networkingLinux/Unix/Windows
The curl command is one of the most frequently used commands in Linux/Unix-like operating systems. curl The curl command is a versatile tool for transferring data to or from a server using various protocols. It supports HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP, POP3, IMAP, SMTP, and many more. Primarily used for testing APIs, downloading files, and data transfer operations without user interaction.

Quick Reference

Command Name:

curl

Category:

networking

Platform:

Linux/Unix/Windows

Basic Usage:

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

Common Use Cases

  • 1

    API testing

    Test RESTful APIs with different HTTP methods and data formats

  • 2

    File downloads

    Download files from various sources including HTTP, FTP, and more

  • 3

    Web scraping

    Extract data from websites in scriptable, non-interactive manner

  • 4

    Server testing

    Verify server configurations, TLS/SSL settings, and response headers

Syntax

curl [options] [URL...]

Options

Option Description
-A, --user-agent Specify the User-Agent string to send to the server
-b, --cookie Send cookies from a string or file
-c, --cookie-jar Write cookies to a file after operation
-C, --continue-at Resume a download from a specific position
-d, --data Send data in a POST request
-F, --form Send a multipart/form-data request
-H, --header Add custom headers to the request
-I, --head Fetch headers only (HTTP HEAD request)
-k, --insecure Allow insecure connections (skip SSL certificate verification)
-L, --location Follow redirects
-m, --max-time Set a maximum time for the transfer
-o, --output Write output to a file instead of stdout
-O, --remote-name Save output to a file using the remote filename
-s, --silent Silent mode (don't show progress or errors)
-S, --show-error Show errors even in silent mode
-u, --user Specify username and password for authentication
-v, --verbose Make the operation more verbose (show detailed information)
-X, --request Specify the request method (GET, POST, PUT, DELETE, etc.)
--limit-rate Limit the transfer speed
--proxy Use the specified proxy
--ssl-reqd Require SSL/TLS for the connection

Examples

How to Use These Examples

The examples below show common ways to use the curl command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Examples:

curl https://example.com

Fetch and display the contents of a website.

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

Download the contents of a website and save it to a file.

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

Download a file and save it with the same name as on the remote server.

Advanced Examples:

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

Send a POST request with form data to an API endpoint.

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

Send a POST request with JSON data and a custom header.

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

Access a protected resource using basic authentication.

curl -C - -O https://example.com/largefile.zip

Resume a previously interrupted download.

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

Follow HTTP redirects to the final destination.

curl -v https://example.com

Use verbose mode to see detailed request and response information.

curl -I https://example.com

Fetch only the HTTP headers of a URL.

curl --cookie "name=value" https://example.com

Send a request with a cookie.

curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com

Specify a custom User-Agent header.

curl --limit-rate 100K https://example.com/largefile.zip -O

Limit the download speed to 100 KB/s.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Key Points:

  • curl is a versatile command-line tool for data transfer with HTTP(S) and many other protocols
  • It can be used for both downloading and uploading data
  • curl supports various authentication methods including Basic, Digest, NTLM, Negotiate, etc.
  • It's commonly used for testing RESTful APIs and web services
  • curl can use proxies, SSL certificates, and follow redirects
  • It's highly scriptable and can be used in automated workflows
  • curl is available on virtually all UNIX-like systems and Windows platforms

HTTP Methods:

  • GET - Retrieve data (default method)
  • POST - Submit data to be processed
  • PUT - Update existing resources
  • DELETE - Remove resources
  • HEAD - Retrieve just the headers of a response
  • OPTIONS - Describe communication options for a resource
  • PATCH - Apply partial modifications to a resource
  • TRACE - Echo the received request for debugging

Data Formats:

  • Form data with -d name=value
  • JSON with -d '{"name": "value"}' and appropriate Content-Type header
  • File uploads with -F "file=@path/to/file"
  • Raw binary data with --data-binary
  • URL-encoded data with --data-urlencode

Security Considerations:

  • Use -k (insecure) option with caution, as it bypasses SSL certificate verification
  • Be careful with passwords in command-line arguments as they may be visible in process listings
  • Consider using -K to load sensitive information from a config file instead
  • When automating scripts, ensure that error handling is properly implemented
  • HTTPS should be preferred over HTTP for secure communication
  • Consider using OAuth tokens rather than embedding credentials directly

Common Use Cases:

  • Testing RESTful API endpoints
  • Downloading files from web servers or FTP sites
  • Web scraping for data acquisition
  • System monitoring and health checks
  • Automated deployments and continuous integration
  • Sending webhook notifications
  • Interacting with IoT devices over HTTP

Related Commands:

  • wget - Non-interactive download of files from the web
  • httpie - User-friendly HTTP client with colorized output
  • lynx - Text-based web browser
  • nc (netcat) - TCP/UDP connection and listening tool
  • telnet - Interactive communication with another host
  • ftp - File Transfer Protocol client
  • ssh - Secure Shell client for remote login
  • scp/sftp - Secure file transfer tools

Tips & Tricks

1

Use -o to save response to a file: curl -o filename.html https://example.com

2

Resume partial downloads with -C -: curl -C - -O https://example.com/largefile.zip

3

Follow redirects with -L: curl -L http://example.com/redirecting-page

4

See detailed request/response info with -v: curl -v https://example.com

5

Send custom headers with -H: curl -H "Accept: application/json" https://api.example.com

6

Set request method with -X: curl -X POST https://api.example.com

7

Send form data with -d: curl -d "param1=value1&param2=value2" https://api.example.com

8

Send JSON with correct headers: curl -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com

9

Authenticate with -u: curl -u username:password https://example.com

10

Download multiple files with {pattern}: curl -O "https://example.com/file[1-10].txt"

Common Use Cases

API testing

Test RESTful APIs with different HTTP methods and data formats

File downloads

Download files from various sources including HTTP, FTP, and more

Web scraping

Extract data from websites in scriptable, non-interactive manner

Server testing

Verify server configurations, TLS/SSL settings, and response headers

Automation

Integrate with scripts and CI/CD pipelines for automated operations

Related Commands

wget

wget

View command

httpie

httpie

View command

nc

nc

View command

scp

scp

View command

sftp

sftp

View command

ssh

ssh

View command

lynx

lynx

View command

telnet

telnet

View command

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the curl command works in different scenarios.

$ curl
View All Commands