If you’ve ever worked on the command line and needed to test an API, download a file, or just peek under the hood of a website—chances are you’ve met curl
.
But if you’re new to it:
curl
(short for “Client URL”) is a lightweight yet powerful command-line tool for transferring data across URLs. It supports nearly every protocol you can think of—HTTP, HTTPS, FTP, SCP, SFTP, and more.
Whether you’re a developer debugging APIs, a sysadmin juggling files, or just someone curious about how the web works behind the scenes, curl
is one of the most versatile tools you can keep in your toolbox.
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Start Learning Linux today - Free!And while curl
has hundreds of options, the good news is: you don’t need to memorize them all. Mastering just a handful will take you a long way.
Let’s dive into 20 essential curl
tips that will level up your terminal game.
Table of Contents
1. Save Output to a File
By default, curl
dumps the response right into your terminal. Great for quick checks—less great when you’re downloading a 10MB HTML page.
Want to save the output to a file? You’ve got two options:
# Save to a specific filename
curl -o mypage.html <https://example.com>
# Save using the remote filename (uppercase -O)
curl -O <https://example.com/archive.zip>
2. Just Show the Headers
Sometimes you don’t care about the content—you just want to see what the server is saying.
curl -I <https://example.com>
This sends an HTTP HEAD
request and displays only the headers. Great for checking status codes or content types.
3. Show Headers with the Body
Want the full picture—headers and body? Use -i
:
curl -i <https://example.com>
This is useful when debugging how the server responds, especially with APIs.
4. Follow Redirects
Some URLs bounce you around with 301 or 302 redirects. By default, curl
doesn’t follow them.
To go with the flow:
curl -L <https://short.url/resource>
This will chase redirects until it gets to the final destination.
5. Send a POST Request
While curl
defaults to GET, you can send any HTTP method using -X
:
curl -X POST -d "name=Alice&project=curl_tips" <https://api.example.com/users>
Use -d
to send data in the request body—perfect for forms and APIs.
6. Send JSON Like a Pro
APIs love JSON. Here’s how to send it with curl
:
curl -X POST -H "Content-Type: application/json" \\
-d '{"username":"bob", "score":100}' <https://api.example.com/submit>
Setting the right headers is key.
7. Add Custom Headers
Speaking of headers—need to pass an API key or auth token?
curl -H "Authorization: Bearer mytoken" \\
-H "Accept: application/json" <https://api.example.com/data>
You can add as many headers as you like using multiple -H
flags.
8. Use Basic Auth
Some endpoints need a simple username/password combo. curl
makes that easy:
curl -u admin:pa$$w0rd <https://protected.example.com/data>
If you leave off the password (-u admin
), curl
will prompt you.
9. Get Verbose Output
Something not working? Add -v
to get a play-by-play:
curl -v <https://example.com>
This prints request headers, response headers, and connection details—your new debugging best friend.
10. Resume Interrupted Downloads
Ever lose a connection mid-download? Don’t start over—resume!
curl -O -C - <https://example.com/largefile.zip>
Just make sure the server supports partial downloads (most do).
11. Quiet Mode for Scripting
If you’re scripting with curl
, you might want it to keep quiet:
curl -sS -o output.json <https://api.example.com/status>
s
: silentS
: show errors only
Great for automation and cron jobs.
12. Fake Your User-Agent
Some servers behave differently depending on who’s asking. To pretend you’re a browser:
curl -A "Mozilla/5.0" <https://example.com>
Or use a custom one to identify your script:
curl -A "MyScript/1.0" <https://api.example.com/data>
13. Handle Cookies
To persist sessions across requests, save and reuse cookies:
# Save cookies from login
curl -c cookies.txt -X POST -d "user=admin&pass=secret" <https://example.com/login>
# Reuse cookies in next request
curl -b cookies.txt <https://example.com/dashboard>
Great for testing login flows.
14. Set Timeouts
Don’t let your script hang forever on a bad connection.
curl --connect-timeout 5 -m 30 <https://example.com>
-connect-timeout
: max time to establish connectionm
: max total time
15. Upload Files
You can upload files via FTP, SFTP, or even HTTP PUT:
curl -T file.txt <ftp://ftp.example.com/uploads/>
curl -T image.png -X PUT <https://api.example.com/upload/image.png>
16. Submit Forms with Files
Simulate browser-style form submissions with file uploads:
curl -F "user_name=Alice" \\
-F "profile_pic=@/path/to/avatar.jpg;type=image/jpeg" \\
<https://example.com/profile_update>
Perfect for uploading images, PDFs, or any multipart data.
17. Use a Proxy
Working behind a firewall or testing how traffic behaves through a proxy?
curl -x <http://proxy.example.com:8080> <https://target.site.com>
Or use SOCKS5:
curl --socks5 socks-proxy.local:1080 <https://target.site.com>
18. Extract Info After Transfer
Want just the HTTP status code or download time?
curl -s -o /dev/null -w "Status: %{http_code}\\nTime: %{time_total}s\\n" <https://example.com>
This is incredibly useful in scripts or health checks.
19. Ignore SSL Certificate Warnings
In dev environments, you might hit a self-signed cert. To ignore validation (⚠️ use with caution):
curl -k <https://localhost:8443/api/status>
Never use this in production unless you’re absolutely sure.
20. Force IPv4 or IPv6
Test connectivity by forcing IP version:
curl -4 <https://example.com> # IPv4 only
curl -6 <https://example.com> # IPv6 only
Useful for debugging DNS or network issues.
Wrapping Up
And there you have it—20 practical curl
tips to make your terminal life easier.
If you’re just getting started, don’t worry about memorizing everything. Pick the ones that solve real problems for you now, and revisit the others as needed. curl
’s man page (man curl
) is always there when you need to dig deeper.