wget
Overview
wget is a non-interactive downloader for HTTP(S), FTP, and related protocols. It shines at recursive site fetches, resume, rate limiting, and simple “get this URL into a file” scripts. For complex APIs and arbitrary methods, curl is usually better; for bulk downloads and mirroring, wget is often clearer.
Syntax
wget [OPTIONS] [URL...]
wget [OPTIONS] -i url-list.txtCommon Options
| Option | Description |
|---|---|
-O file |
Write to this filename (- = stdout) |
-o logfile |
Write messages to log file |
-c |
Continue / resume partial download |
-q |
Quiet |
-v / -nv |
Verbose / non-verbose |
-b |
Go to background after start |
-P dir |
Directory prefix for saved files |
-N |
Timestamping (re-get only if newer) |
--limit-rate=RATE |
Throttle (e.g. 500k) |
--timeout=SECS |
Network timeout |
--tries=N |
Retry count (0 = infinite) |
--retry-connrefused |
Retry even on connection refused |
-U agent |
User-Agent string |
--header='K: V' |
Extra HTTP header |
--user= / --password= |
Auth (prefer netrc; see Safety) |
-r |
Recursive download |
-l N |
Recursion depth |
-np |
No parent (stay under URL path) |
-k |
Convert links for local viewing |
-p |
Page requisites (CSS/images for HTML) |
-m |
Mirror shorthand (-r -N -l inf --no-remove-listing) |
-A / -R |
Accept / reject filename patterns |
--spider |
Check existence without downloading |
--no-check-certificate |
Skip TLS verify (avoid) |
Safety
- Do not put passwords on the command line (
pscan see them). Prefer~/.wgetrcpermissions600or.netrcwith tight modes, or prompt-based tools. - Recursive
-rcan pull far more than intended (entire sites). Use-np,-l, and-A/-Rlimits. --no-check-certificatedisables TLS verification — only for lab debugging of broken certs, never production automation.- Respect site
robots.txtand terms;-e robots=offexists but is often rude or disallowed.
Examples with Explanations
Simple download (keeps remote name)
wget https://example.com/files/app-1.2.3.tgzSave under a specific name
wget -O app.tgz https://example.com/files/app-latest.tgzResume interrupted download
wget -c https://example.com/big.isoQuiet download into a directory
mkdir -p ~/downloads
wget -q -P ~/downloads https://example.com/tool.debRate-limited fetch with retries
wget --limit-rate=1m --tries=5 --timeout=30 \
https://example.com/dataset.tar.gzMultiple URLs from a file
wget -i urls.txt -P ./artifacts/One URL per line in urls.txt.
Spider: check if URL is reachable
wget --spider -q https://example.com/health && echo up || echo downAuthenticated download (prefer netrc)
# ~/.netrc (chmod 600):
# machine example.com login USER password SECRET
wget https://example.com/private/build.zipCustom header (e.g. token) without logging token in shell history carefully
wget --header="Authorization: Bearer ${TOKEN}" \
-O release.json https://api.example.com/v1/releaseStill prefer env vars over pasting secrets into shell history.
One-page offline copy (HTML + assets)
wget -p -k -P ./mirror https://example.com/docs/intro.html-p gets page requisites; -k rewrites links for local browsing.
Bounded recursive mirror of a docs tree
wget -r -np -nH -l 3 -P ./docs \
https://example.com/manual/-np— do not ascend to parent
-nH— no host-prefixed directory
-l 3— depth limit
Timestamped re-sync of a single artifact
wget -N https://example.com/app.tgzSkips download if local file is already up to date (server must send proper timestamps).
Understanding Output
Default progress shows percent, bar, speed, and ETA. -q silences progress (errors still appear unless fully quieted). HTTP error codes produce non-zero exit status in modern wget — check $? in scripts. Partial files remain when interrupted unless you clean them; -c reuses them.
Notes & Pitfalls
-Owith multiple URLs concatenates into one file — usually wrong; use-Por separate invocations.- Recursive mode creates directory trees; know where
-Ppoints before filling the disk. - Some CDNs need a browser-like User-Agent (
-U) or extra headers; prefer fixing the URL/API over spoofing when you control the service. - For REST APIs with POST/JSON, use
curl;wgetcan POST (--post-data) but is less ergonomic. - On Ubuntu, package is typically
wgetfromapt; GNU wget 1.x is the common default (wget --version).
Additional Resources
man wget/usr/share/doc/wget/on Debian/Ubuntu packages