Sagar.BlogArticle
All posts
All posts
Linux

curl & wget — Download Files from the Command Line

Transfer data and download files using curl and wget. Learn the differences and when to use each tool.

March 11, 20255 min read
linuxnetworkingcurlwgethttp

curl — Transfer URLs

curl transfers data to/from servers using many protocols. It's especially useful for API testing and custom HTTP requests.

curl https://example.com                     # Print page to stdout

# Save output
curl -o page.html https://example.com        # Named file
curl -O https://example.com/file.zip         # Original filename

# HTTP options
curl -L https://shortened.url                # Follow redirects
curl -I https://example.com                  # Headers only
curl -s https://api.example.com/data         # Silent mode

# POST requests
curl -X POST -d "name=sagar" https://api.example.com

# JSON POST
curl -X POST -H "Content-Type: application/json" \
     -d '{"name": "sagar"}' https://api.example.com

# Authentication
curl -u username:password https://api.example.com

# Resume download
curl -C - -O https://example.com/large-file.zip

wget — Web Downloader

wget is designed for downloading files — it saves to disk by default and supports recursive downloads.

wget https://example.com/file.zip             # Download file
wget -O output.zip https://example.com/file.zip  # Rename

wget -b https://example.com/large.zip        # Background
wget -c https://example.com/large.zip        # Resume
wget -q https://example.com/file.zip         # Quiet mode

# Recursive / Mirror
wget -r -l 2 https://example.com            # Recursive depth 2
wget -m https://example.com                 # Mirror site

wget --limit-rate=1m https://example.com/file.zip  # Throttle

curl vs wget

Featurecurlwget
ProtocolsMany (HTTP, FTP, SMTP…)HTTP, FTP
API testing✅ Excellent❌ Limited
Resume download✅ Yes✅ Yes
Recursive download❌ No✅ Yes
Stdout by default✅ Yes❌ Saves to file

Use curl for API testing and scripting HTTP requests. Use wget for downloading files, especially recursively or in the background.

Quick Check

Which flag makes curl follow HTTP redirects?

Exercise

Use curl to fetch the JSON from https://jsonplaceholder.typicode.com/todos/1 and display it.