Save Output to a File

Command:

1
curl -o output.html http://example.com

What it does:
Saves the content of the webpage to a file named output.html.

Follow Redirects

1
curl -L http://example.com

What it does:
Follows any HTTP redirects and fetches the final destination page.


Show HTTP Headers

Command:

1
curl -I http://example.com

What it does:
Displays only the HTTP headers (e.g., status code, content type) of the requested page.


Download a File

Command:

1
curl -O http://example.com/file.zip

What it does:
Downloads a file from the URL and saves it with the same name as on the server.


Send a GET Request with Parameters

Command:

1
curl "http://example.com/api?param1=value1&param2=value2"

What it does:
Sends a GET request with query parameters to the server.


Send Data with a POST Request

Command:

1
curl -X POST -d "key1=value1&key2=value2" http://example.com/api

What it does:
Sends data using the POST method to an API or server.


Include Custom Headers

Command:

1
curl -H "Authorization: Bearer YOUR_TOKEN" http://example.com/api

What it does:
Sends a request with a custom HTTP header, such as an API authorization token.


Send JSON Data

Command:

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

What it does:
Sends JSON-formatted data to an API endpoint using a POST request.


Test a Server’s Response Time

Command:

1
curl -w "Time: %{time_total}s\n" -o /dev/null -s http://example.com

What it does:
Measures the total time taken to get a response from the server without saving the content.


Download a File with Authentication

Command:

1
curl -u username:password -O http://example.com/protected/file.zip

What it does:
Downloads a file from a password-protected area by providing login credentials.


Upload a File

Command:

1
curl -X POST -F "file=@/path/to/file.txt" http://example.com/upload

What it does:
Uploads a file to a server via an HTTP POST request.


Use Proxy

Command:

1
curl -x http://proxyserver:port http://example.com

What it does:
Routes the request through a proxy server.


Limit Download Speed

Command:

1
curl --limit-rate 100k http://example.com/file.zip

What it does:
Limits the download speed to 100 KB/s.


Resume a Download

Command:

1
curl -C - -O http://example.com/largefile.zip

What it does:
Resumes an interrupted download of a file.


Perform FTP Operations

Command:

1
curl ftp://example.com/file.txt --user username:password

What it does:
Downloads a file from an FTP server using credentials.


Debug Requests

Command:

1
curl -v http://example.com

What it does:
Shows detailed information about the request and response, useful for debugging.


Use a Specific Protocol

Command:

1
curl --http2 http://example.com

What it does:
Forces the request to use HTTP/2 protocol.


Suppress Output

Command:

1
curl -s http://example.com

What it does:
Runs curl silently, suppressing progress and error messages.


Test Authentication

Command:

1
curl -u user:pass http://example.com

What it does:
Tests HTTP Basic Authentication by providing a username and password.


Send a DELETE Request

Command:

1
curl -X DELETE http://example.com/api/resource/123

What it does:
Sends a DELETE request to remove a resource on the server.


Save Cookies

Command:

1
curl -c cookies.txt http://example.com

What it does:
Saves server-set cookies to a file.


Use Saved Cookies

Command:

1
curl -b cookies.txt http://example.com

What it does:
Uses the previously saved cookies for the request.


Use Multiple URLs

Command:

1
curl -O http://example.com/file1.txt -O http://example.com/file2.txt

What it does:
Downloads multiple files in a single command.