Chapter 36: Bash URL Transfer (curl)
Bash URL Transfer (curl)! 😄
curl (written in lowercase) is one of the most powerful and most used tools in the entire Bash/Linux world — especially for developers, DevOps people, API testers, and anyone who talks to the internet from the command line.
What does “curl” stand for? client URL
It’s a command-line tool that lets you transfer data to or from a server using URLs. It supports tons of protocols like HTTP, HTTPS, FTP, SFTP, SMTP (email), and many more — but 95% of people use it only for HTTP/HTTPS (web stuff and APIs).
Think of curl as your personal web browser without any graphical interface — it can fetch web pages, download files, send data to servers, test APIs, check headers, follow redirects, pretend to be Chrome/Firefox, and much more — all from your terminal in Hyderabad!
First: Check if You Have curl (Almost Everyone Does)
Type this right now:
|
0 1 2 3 4 5 6 |
curl --version |
You should see something like:
|
0 1 2 3 4 5 6 7 8 |
curl 8.5.0 (x86_64-pc-linux-gnu) libcurl/8.5.0 ... Protocols: ... Features: AsynchDNS HSTS HTTPS-proxy IPv6 Largefile NTLM NTLM_WB SSL ThreadSafe UnixSockets ... |
If not installed (rare), on Ubuntu/Debian:
|
0 1 2 3 4 5 6 |
sudo apt update && sudo apt install curl |
On macOS (usually pre-installed), or Fedora:
|
0 1 2 3 4 5 6 |
sudo dnf install curl |
Basic Syntax
|
0 1 2 3 4 5 6 |
curl [options] [URL] |
No options → just fetches the page and prints it to screen (like a very basic browser).
1. Super Basic – Fetch a Web Page
|
0 1 2 3 4 5 6 |
curl https://example.com |
→ Dumps the entire HTML of the homepage right in your terminal.
Want cleaner output? Pipe to less:
|
0 1 2 3 4 5 6 |
curl https://example.com | less |
Or just the first few lines:
|
0 1 2 3 4 5 6 |
curl https://example.com | head -n 10 |
2. Save the Output to a File (Download!)
Two very common ways:
- -o → specify your own filename
|
0 1 2 3 4 5 6 |
curl -o mypage.html https://example.com |
- -O (capital O) → use the original filename from the URL
|
0 1 2 3 4 5 6 |
curl -O https://example.com/images/logo.png |
→ Saves as logo.png in current folder.
Resume interrupted download (super useful for big files):
|
0 1 2 3 4 5 6 |
curl -C - -O https://bigfile.zip |
-C – = continue from where left off.
3. Show Only Headers (Check Server Response)
|
0 1 2 3 4 5 6 |
curl -I https://google.com |
→ -I = HEAD request (only headers, no body)
Output example:
|
0 1 2 3 4 5 6 7 8 9 |
HTTP/2 301 location: https://www.google.com/ content-type: text/html; charset=UTF-8 ... |
Very useful to check status code, redirects, content-type, server type, etc.
4. Follow Redirects (-L)
Many sites redirect (http → https, or short links):
|
0 1 2 3 4 5 6 |
curl -L http://example.com # follows to final https://example.com |
Combine with save:
|
0 1 2 3 4 5 6 |
curl -L -O https://short.link/file.zip |
5. Verbose Mode (-v) – See Everything!
|
0 1 2 3 4 5 6 |
curl -v https://api.github.com |
→ Shows request headers, response headers, SSL handshake — great for debugging!
6. Change HTTP Method & Send Data (API Testing – Most Important!)
By default curl uses GET.
Change method with -X:
|
0 1 2 3 4 5 6 7 8 |
curl -X POST https://httpbin.org/post curl -X PUT https://httpbin.org/put curl -X DELETE https://httpbin.org/delete |
Send data (form or JSON – very common for APIs):
- Simple form data (-d):
|
0 1 2 3 4 5 6 |
curl -d "name=Webliance&city=Hyderabad" https://httpbin.org/post |
- JSON (most modern APIs):
|
0 1 2 3 4 5 6 7 8 9 |
curl -X POST \ -H "Content-Type: application/json" \ -d '{"name":"Webliance","location":"Hyderabad","learning":"Bash"}' \ https://httpbin.org/post |
-H = add header (Content-Type, Authorization, etc.)
7. Authentication (Basic, Bearer Token, etc.)
Basic auth:
|
0 1 2 3 4 5 6 |
curl -u username:password https://example.com/protected |
Bearer token (most APIs like GitHub, Twitter):
|
0 1 2 3 4 5 6 |
curl -H "Authorization: Bearer your_token_here" https://api.github.com/user |
8. Download Files Silently & Progress (-s -S -#)
|
0 1 2 3 4 5 6 7 |
curl -s -O https://example.com/file.zip # silent (no progress) curl -# -O https://example.com/bigfile.zip # simple progress bar |
9. Pretend to be a Browser (User-Agent)
Some sites block command-line tools:
|
0 1 2 3 4 5 6 |
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0" https://example.com |
-A = User-Agent string.
10. Quick Reference Table (Most Used in 2026)
| What you want to do | Command Example | Why useful in real life |
|---|---|---|
| Fetch page | curl https://example.com | Quick check content |
| Download file | curl -O https://…/file.zip | Save images, zips, PDFs |
| Resume download | curl -C – -O https://… | Big files interrupted |
| Only headers | curl -I https://google.com | Check status, redirects |
| Follow redirects | curl -L -o page.html http://… | Handle 301/302 |
| POST JSON to API | curl -X POST -H “Content-Type: application/json” -d ‘{“key”:”value”}’ https://api… | Test/create data in APIs |
| Verbose debug | curl -v https://… | See full request/response |
| Silent download | curl -s -O … | Scripts/cron jobs |
| Auth with token | curl -H “Authorization: Bearer token” … | GitHub, OpenAI, most REST APIs |
Practice Right Now (Try These!)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 1. Basic fetch curl https://httpbin.org/get # 2. Save JSON response curl https://api.github.com/users/webliance > myinfo.json cat myinfo.json # 3. Check headers curl -I https://www.google.com # 4. POST example (test server) curl -X POST -d "username=webliance&city=Hyderabad" https://httpbin.org/post # 5. Download a small image curl -O https://httpbin.org/image/jpeg |
See how easy it is to talk to the internet?
Got it, boss? curl is your Swiss Army knife for the web — once you master it, you’ll use it every day for API testing, downloading, scripting, debugging.
Any part confusing? Want more on JSON APIs, file uploads (-F), cookies (-b -c), or proxies? Or next topic like “wget vs curl” or “curl in scripts”?
Just say — teacher is ready in Hyderabad! Keep curling the web! 🐧🌐😄
