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

    Web data transfer

    Transfer data to and from web servers

  • 2

    API testing

    Test REST APIs and web services

  • 3

    File downloading

    Download files from web servers and FTP sites

  • 4

    Web scraping

    Extract data from web pages and services

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:

Fetch and display the contents of a website
curl https://example.com
Download the contents of a website and save it to a file
curl -o output.html https://example.com
Download a file and save it with the same name as on the remote server
curl -O https://example.com/file.zip

Advanced Examples:

Send a POST request with form data to an API endpoint
curl -X POST -d "name=John&age=25" https://example.com/api
Send a POST request with JSON data and a custom header
curl -X POST -H "Content-Type: application/json" -d '{"name":"John","age":25}' https://example.com/api
Access a protected resource using basic authentication
curl -u username:password https://example.com/protected
Resume a previously interrupted download
curl -C - -O https://example.com/largefile.zip
Follow HTTP redirects to the final destination
curl -L https://example.com/redirect
Use verbose mode to see detailed request and response information
curl -v https://example.com
Fetch only the HTTP headers of a URL
curl -I https://example.com
Send a request with a cookie
curl --cookie "name=value" https://example.com
Specify a custom User-Agent header
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://example.com
Limit download speed to 100KB/s
curl --limit-rate 100K https://example.com/largefile.zip -O

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

Common Use Cases

Web data transfer

Transfer data to and from web servers

API testing

Test REST APIs and web services

File downloading

Download files from web servers and FTP sites

Web scraping

Extract data from web pages and services

Network troubleshooting

Test network connectivity and HTTP services

Related Commands

These commands are frequently used alongside curl or serve similar purposes:

Use Cases

1

Web data transfer

Transfer data to and from web servers

2

API testing

Test REST APIs and web services

3

File downloading

Download files from web servers and FTP sites

4

Web scraping

Extract data from web pages and services

5

Network troubleshooting

Test network connectivity and HTTP services

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