curl & wget

curl and wget transfer data over the network — fetching pages, files and calling APIs.

Syntaxcurl [options] url wget [options] url

Both tools download from URLs, but they lean in different directions.

curl — talk to servers

curl prints a URL's response to the screen by default and is the standard tool for testing HTTP APIs.

  • curl https://example.com — print the response.
  • curl -O url — save to a file with its original name.
  • curl -I url — fetch only the response headers.
  • curl -X POST -d 'a=1' url — send data.

wget — download files

wget is geared toward downloading. It saves to a file automatically and can even mirror whole sites.

Example

Example · bash
# Print a web page or API response
curl https://api.github.com

# See just the HTTP headers
curl -I https://example.com

# Send JSON to an API
curl -X POST -H "Content-Type: application/json" \
     -d '{"name":"alice"}' https://api.example.com/users

# Download a file with wget
wget https://example.com/archive.tar.gz

When to use it

  • A developer uses 'curl -s https://api.github.com/repos/user/repo | jq .stargazers_count' to fetch and parse API data from the terminal.
  • A sysadmin uses 'wget -r -np https://docs.example.com/' to mirror documentation for offline access.
  • A CI pipeline uses 'curl -f -o /dev/null https://app.example.com/health' to check if a deployment is healthy.

More examples

Fetch a URL and inspect response

Shows curl fetching a URL with -i to include headers and -I to send a HEAD request for headers only.

Example · bash
# Get response body
curl https://httpbin.org/get

# Show response headers too
curl -i https://httpbin.org/get

# Only show headers
curl -I https://example.com

POST JSON to an API

Uses curl to send a POST request with a JSON body and authentication header, covering REST API calls.

Example · bash
curl -X POST https://api.example.com/users \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer TOKEN' \
  -d '{"name":"Alice","role":"admin"}'

Download files with wget

Shows wget for file downloads with -O to rename the output, -q for quiet mode, and -c to resume.

Example · bash
# Download and save with original filename
wget https://example.com/archive.tar.gz

# Download quietly (no progress) to a specific path
wget -q -O /tmp/latest.zip https://example.com/latest.zip

# Resume an interrupted download
wget -c https://example.com/large_file.iso

Discussion

  • Be the first to comment on this lesson.
curl & wget — Linux | SoundsCode