How To Use cURL Like a Pro

If you’re already comfortable in the Linux terminal — using wget for downloads, managing systems on Ubuntu 24.04.4, finding files with locate, monitoring performance with top, organizing directories with mkdir, or writing automation scripts using Bash heredocs — then you’re ready to level up.

The next logical step is mastering cURL.

cURL is not just a download tool. It is a professional-grade network client that allows you to interact directly with web servers, REST APIs, authentication systems, proxies, and cloud services — all from your terminal.

In this in-depth guide, I’ll walk you through practical, real-world use cases and 25 detailed cURL commands that will make you a stronger sysadmin.


What Makes cURL So Powerful?

Unlike wget, which focuses on retrieving files, cURL is built around:

  • Precise control over HTTP methods
  • Full visibility of request and response headers
  • Authentication support
  • API testing and automation
  • Data upload and download
  • Advanced debugging

If you manage Linux servers, APIs, containers, CI/CD systems, or infrastructure in general — cURL is not optional.


25 cURL Commands (With Detailed Explanations)

Each example below explains what problem it solves, why it matters, and how it works.


1. Basic GET Request

Before doing anything advanced, you must understand the default behavior.

By default, cURL performs an HTTP GET request and prints the response body to stdout.

This is useful for:

  • Checking if a website responds
  • Fetching API data
  • Quick debugging
curl https://example.com

If the server responds correctly, you’ll see the raw HTML or JSON returned.


2. Silent Mode for Scripts

In automation scripts or cron jobs, the progress meter is noise. It can clutter logs and make output hard to parse.

The -s (silent) option removes the progress bar and error messages.

curl -s https://example.com

This is critical for clean script output.


3. Save Output to a Specific File

Sometimes you don’t want output in the terminal — you want it saved.

The -o option lets you specify the output filename manually.

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

Useful when:

  • Archiving API responses
  • Saving HTML snapshots
  • Downloading configuration templates

4. Keep the Remote Filename Automatically

If you’re downloading installation packages or backups, you may want to preserve the original filename.

curl -O https://example.com/backup.tar.gz

This saves the file exactly as named by the server.


5. Follow Redirects (Critical in Production)

Many production URLs return 301 or 302 redirects.

Without -L, cURL will only show the redirect response — not the final content.

curl -L https://example.com

This ensures you always reach the final destination.

Essential when testing:

  • Reverse proxies
  • Load balancers
  • CDN configurations

6. Inspect Response Headers Only

As a sysadmin, headers matter.

You often need to check:

  • HTTP status codes
  • Cache headers
  • Server software
  • Security headers

Use -I (capital i):

curl -I https://example.com

This makes a HEAD request instead of GET.


7. See Headers and Body Together

When debugging complex API responses, you may want both headers and body.

curl -i https://example.com

This helps diagnose:

  • Authentication failures
  • CORS issues
  • Incorrect content types

8. Send POST Form Data

Some systems still expect application/x-www-form-urlencoded data (classic form submissions).

curl -X POST -d "username=admin&password=secret" https://example.com/login

Here:

  • -X POST sets method
  • -d sends form data

cURL automatically sets Content-Type correctly when using -d.


9. Send JSON Payload

Modern APIs use JSON.

To send JSON properly, you must:

  1. Specify the method
  2. Add the correct Content-Type header
  3. Provide JSON data
curl -X POST https://api.example.com/users \
     -H "Content-Type: application/json" \
     -d '{"name":"John","role":"admin"}'

This is fundamental for interacting with REST APIs.


10. PUT Request for Updating Resources

PUT is commonly used to replace or update resources.

curl -X PUT https://api.example.com/users/1 \
     -H "Content-Type: application/json" \
     -d '{"role":"editor"}'

This command updates user ID 1.

Very common in:

  • Kubernetes APIs
  • Cloud providers
  • Configuration management systems

11. DELETE a Resource

Automated cleanup is part of good infrastructure hygiene.

curl -X DELETE https://api.example.com/users/1

Useful for:

  • Removing test data
  • Cleaning expired sessions
  • Automating teardown processes

12. Add Custom Headers (Bearer Tokens)

APIs commonly require token authentication.

curl -H "Authorization: Bearer TOKEN" https://api.example.com/data

Without headers, many APIs return 401 Unauthorized.

Mastering headers is essential for DevOps workflows.


13. Basic Authentication

Some legacy systems use basic HTTP authentication.

curl -u user:password https://example.com

cURL encodes credentials automatically.

Important when testing internal admin panels.


14. Save Cookies to a File

When login systems create session cookies, you must preserve them.

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

This stores all cookies sent by the server.


15. Reuse Cookies in Later Requests

To simulate logged-in sessions:

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

This is powerful for:

  • Testing web apps
  • Simulating user sessions
  • Scripting login flows

16. Upload a File

For backup uploads or API file endpoints:

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

The -F flag sends multipart/form-data.

Common in:

  • Artifact repositories
  • Cloud storage systems
  • CI/CD uploads

17. Resume Interrupted Downloads

Large ISO downloads sometimes break.

Instead of restarting:

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

-C - resumes from the last byte downloaded.

Critical for unstable connections.


18. Set Maximum Execution Time

To prevent hanging scripts:

curl --max-time 10 https://example.com

If no response within 10 seconds, cURL exits.

This is vital in automation.


19. Verbose Debug Mode

When things break, use verbose mode.

curl -v https://example.com

This shows:

  • Request headers
  • TLS handshake
  • Response headers
  • Redirect flow

Invaluable for troubleshooting SSL or proxy issues.


20. Extract Only HTTP Status Code

Monitoring systems often only care about status codes.

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

This prints only:

200

Perfect for uptime checks.


21. Set Custom User-Agent

Some services block default curl user agents.

curl -A "Mozilla/5.0" https://example.com

Allows testing different client behaviors.


22. Limit Download Speed

Prevent network saturation:

curl --limit-rate 100k -O https://example.com/file.iso

Important on production servers with shared bandwidth.


23. Use a Proxy Server

Enterprise networks often require proxies.

curl -x http://proxy:8080 https://example.com

Works with authentication if needed.


24. Ignore SSL Certificate Errors

In development environments with self-signed certificates:

curl -k https://dev.internal.local

Never use -k in production scripts.


25. Use Bash Heredoc for Clean JSON Payloads

When payloads grow complex, inline JSON becomes unreadable.

Heredocs solve this elegantly:

curl -X POST https://api.example.com/create \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "name": "Production Server",
  "ip": "192.168.1.10",
  "role": "web"
}
EOF

This keeps scripts clean and maintainable.

Professional automation always favors readability.


Final Thoughts

Mastering cURL changes how you interact with the web from Linux.

Instead of relying on browsers or external tools, you:

  • Inspect
  • Debug
  • Automate
  • Validate
  • Deploy

Directly from the terminal.

If you’re serious about becoming a better sysadmin, DevOps engineer, or infrastructure specialist, spend time practicing these commands and experimenting with real APIs.

The more comfortable you get with cURL, the more confident you become in diagnosing networked systems.

And that’s where real Linux mastery begins.

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *