wget Command in Linux: Syntax, Options & Download Examples

wget downloads files over HTTP, HTTPS, and FTP without a browser. It supports resume, retries, mirrors, batch URL lists, and quiet automation from scripts and cron jobs.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

wget Command in Linux: Syntax, Options & Download Examples
About wget downloads files over HTTP, HTTPS, and FTP without a browser. It supports resume, retries, mirrors, batch URL lists, and quiet automation from scripts and cron jobs.
Tested on Ubuntu 25.04 (Plucky Puffin); GNU Wget 1.24.5; kernel 7.0.0-27-generic
Package wget
Man page wget(1)
Privilege none
Distros

Preinstalled or available on virtually all Linux distros (wget package).

APIs and flexible HTTP verbs: curl.

wget — quick reference

Basic downloads

Fetch a URL to the current directory or a path you choose. Examples use https://example.com — a safe documentation domain.

When to use Command
Download using the remote filename wget https://example.com
Save under a specific filename wget -O page.html https://example.com
Save into a directory (creates it if needed) wget -P /tmp/dl https://example.com
Check that a URL exists without saving body wget --spider -q https://example.com
Print server response headers wget -S --spider https://example.com

Resume, retries, and rate limits

When to use Command
Continue a partial download wget -c https://example.com/large.iso
Retry up to 10 times on failure wget -t 10 https://example.com
Unlimited retries (0 means infinite) wget -t 0 https://example.com
Cap download speed (example 500 KB/s) wget --limit-rate=500k https://example.com
Wait 5 seconds between retries wget --waitretry=5 -t 10 https://example.com

Batch and background

When to use Command
Download every URL listed in a file wget -i urls.txt
Quiet mode for scripts wget -q -O out.html https://example.com
Log messages to a file wget -o wget.log https://example.com
Run in the background wget -b https://example.com

Timestamping and clobber control

When to use Command
Skip download if local file is newer or same age wget -N https://example.com/file
Do not overwrite an existing file wget -nc -O page.html https://example.com

Recursive and mirror (use carefully)

When to use Command
Recursive download (respect site rules) wget -r -l 2 https://example.com/
Mirror mode (timestamping + infinite depth by default) wget -m https://example.com/
Stay under one directory (no parent paths) wget -r -np https://example.com/dir/
Flatten paths into the current directory wget -r -nd https://example.com/dir/

Authentication and TLS

When to use Command
HTTP basic auth (prefer --ask-password) wget --user=USER --ask-password https://example.com/
Custom header (API token) wget --header="Authorization: Bearer TOKEN" -O out.json https://api.example.com/
Skip TLS verification (lab only — insecure) wget --no-check-certificate https://selfsigned.local/

wget — command syntax

Synopsis from wget --help on Ubuntu 25.04 (GNU Wget 1.24.5):

text
wget [OPTION]... [URL]...

With no URL, wget can read links from -i or standard input. Options before URLs apply to all files retrieved in that run.


wget — command examples

Essential Download and custom filename

The simplest fetch stores index.html in the current directory. -O picks the local name explicitly — useful in scripts.

bash
cd /tmp && rm -f example-dl.html
wget -q -O /tmp/example-dl.html https://example.com
ls -la /tmp/example-dl.html
head -c 60 /tmp/example-dl.html; echo

Sample output:

text
-rw-r--r-- 1 root root 559 Jul  1 02:26 /tmp/example-dl.html
<!doctype html><html lang="en"><head><title>Example Domain</title>

Remove the test file when finished: rm -f /tmp/example-dl.html.

Essential Target directory and spider check

-P creates the destination directory. --spider checks reachability without writing the response body — handy in health checks.

bash
rm -rf /tmp/wget-dl && mkdir -p /tmp/wget-dl
wget -q -P /tmp/wget-dl https://example.com
ls /tmp/wget-dl/
wget --spider -q https://example.com
echo "spider exit code: $?"
rm -rf /tmp/wget-dl

Sample output:

text
index.html
spider exit code: 0

Exit code 0 means the URL responded successfully.

Common Server headers and retry count

-S with --spider prints response headers to stderr. -t limits retry attempts when the network flaps.

bash
wget -S --spider https://example.com 2>&1 | head -10
wget -q -t 2 -O /tmp/wget-retry.html https://example.com && echo OK
rm -f /tmp/wget-retry.html

Sample output:

text
Spider mode enabled. Check if remote file exists.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Content-Type: text/html
OK

Exact header lines depend on the remote server and any proxy.

Common Batch download from a URL list

Put one URL per line in a text file and pass -i. wget fetches each link in order.

bash
rm -rf /tmp/wget-batch && mkdir -p /tmp/wget-batch
printf '%s\n' 'https://example.com' > /tmp/wget-batch/urls.txt
wget -q -i /tmp/wget-batch/urls.txt -P /tmp/wget-batch/out
ls /tmp/wget-batch/out/
rm -rf /tmp/wget-batch

Sample output:

text
index.html

Add -B / --base when the list contains relative links resolved against one site.

Common Quiet mode and log file

-q silences progress — pair with -O in cron jobs. -o keeps a log when you still need diagnostics.

bash
wget -q -O /tmp/wget-quiet.html https://example.com
wc -c /tmp/wget-quiet.html
wget -o /tmp/wget.log -O /tmp/wget-logged.html https://example.com
tail -1 /tmp/wget.log
rm -f /tmp/wget-quiet.html /tmp/wget-logged.html /tmp/wget.log

Sample output:

text
559 /tmp/wget-quiet.html
2026-07-01 … FINISHED …

The log line format includes timestamp and FINISHED on success.

Advanced Limit download rate

--limit-rate protects shared links or production bandwidth when pulling large artifacts.

bash
wget -q --limit-rate=100k -O /tmp/wget-rate.html https://example.com
ls -la /tmp/wget-rate.html
rm -f /tmp/wget-rate.html

Sample output:

text
-rw-r--r-- 1 root root 559 … /tmp/wget-rate.html

Suffix k or m sets kilobytes or megabytes per second as documented in wget --help.

Advanced Timestamping and no-clobber

-N skips re-downloading when the local copy is up to date. -nc refuses to overwrite an existing target.

bash
wget -q -O /tmp/wget-ts.html https://example.com
wget -nc -q -O /tmp/wget-ts.html https://example.com 2>&1
echo "nc exit: $?"
rm -f /tmp/wget-ts.html

Sample output:

text
File '/tmp/wget-ts.html' already there; not retrieving.
nc exit: 0

Without -nc, wget overwrites by default.

Advanced Shallow recursive fetch — use responsibly

Recursive mode can hammer remote sites. Limit depth with -l and scope with -np. Always respect robots.txt and site policy.

bash
rm -rf /tmp/wget-mirror && mkdir -p /tmp/wget-mirror
wget -q -r -l 1 -np -P /tmp/wget-mirror https://example.com/
find /tmp/wget-mirror -type f | head -5
rm -rf /tmp/wget-mirror

Sample output (paths vary):

text
/tmp/wget-mirror/example.com/index.html

For full offline mirrors, -m adds timestamping and recursion defaults — test on mirrors you own first.


wget — when to use / when not

Use wget when Use something else when
You download files or mirror static sites from scripts You call REST APIs with JSON POST bodies → curl
You need resume (-c) and simple retry knobs You upload multipart forms or need HTTP/2 client features → curl
You batch hundreds of URLs with -i You already use a language HTTP library in application code
You want unattended background downloads (-b) You need interactive browsing → elinks or a browser
You mirror directory trees with built-in recursion You need torrent or metalink clients → specialized tools

wget vs curl

wget curl
Primary job Non-interactive download and mirror Data transfer and API testing
Recursive mirroring Built-in (-r, -m) No native recursive crawl
Resume downloads -c --continue
Output default Saves to file Prints body to stdout
Protocol breadth HTTP, HTTPS, FTP focus Many protocols and verbs
Best for Cron downloads, ISO pulls, mirrors Headers, POST, OAuth APIs

See the curl command for API-oriented examples.


Command One line
scp Copy files over SSH
rsync Efficient sync and transfers
tar Extract archives after download

Browse the full index in our Linux commands reference.


wget — interview corner

What is wget used for in Linux?

GNU wget retrieves files over HTTP, HTTPS, and FTP from the shell. It is non-interactive — ideal for scripts, servers without a GUI, and cron jobs. It follows redirects, retries failures, and can resume partial files with -c.

A strong answer is:

"wget is a non-interactive downloader for HTTP/HTTPS/FTP — I use it in scripts for ISOs and artifacts, with -c to resume and -q for quiet cron runs."

How do you resume an interrupted wget download?

Use -c / --continue. wget asks the server for the rest of the file when the protocol supports range requests.

bash
wget -c https://example.com/large.iso

If resume fails, the server may not support ranges or the local file is corrupt — remove the partial file and restart.

A strong answer is:

"wget -c continues partial downloads when the server supports byte ranges; otherwise I delete the bad partial and restart."

When do you pick wget over curl?

Pick wget for file downloads, batch URL lists (-i), and mirroring static sites. Pick curl when you inspect headers, send POST/PUT with JSON, or debug APIs.

Both can download a single URL; wget defaults to saving a file, curl defaults to stdout.

A strong answer is:

"wget for bulk downloads and mirrors; curl for APIs and custom HTTP methods. wget -O file URL versus curl -o file URL for a single save."

How do you mirror a website with wget?

Mirror mode is wget -m URL (shortcut for recursion, timestamping, and more). In practice, add depth and scope limits:

bash
wget -m -l 2 -np https://example.com/docs/

Respect bandwidth, robots.txt, and legal terms — uncontrolled mirrors can overload small sites.

A strong answer is:

"wget -m for mirror semantics, but I cap depth with -l and scope with -np, and only mirror sites I am allowed to copy."

What does wget --spider do?

--spider performs the request without saving the response body — useful as a URL health check in monitoring scripts. Combine with -S to see response headers.

Exit status is 0 on success, non-zero on failure — testable in shell if statements.

A strong answer is:

"--spider checks reachability without writing a file; I use it in scripts and add -S when I need headers."


Troubleshooting

Symptom Likely cause Fix
ERROR: certificate verification failed TLS trust or hostname mismatch Fix CA bundle; lab-only: --no-check-certificate (insecure)
Resume re-downloads from zero Server lacks range support Remove partial file; try a mirror with ranges
403 Forbidden Auth, hotlink block, or User-Agent filter Add --user / headers; check site policy
Connection refused Service down or wrong port Verify URL; increase -t retries
Proxy errors http_proxy set in environment Unset proxy or set --no-proxy for direct fetch
Recursive wget pulls entire internet Missing -l / -np Add depth and domain limits; never run unbounded -r on production WAN
Empty file with -O URL returned error page Check exit code; use -S to read HTTP status
File already there; not retrieving -nc and existing file Remove file or drop -nc

References

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …