wget
Non-interactive command-line downloader
By CMD Script Team · 4 min read · Last updated
wget [OPTIONS] URL...Options
| Flag | Description |
|---|---|
-O | Write output to a specific file name instead of the URL's basename |
-c | Continue (resume) a partially downloaded file |
-r | Recursively download, following links (e.g. to mirror a site) |
-b | Go to background immediately after starting, logging to wget-log |
-q | Quiet mode, suppress output |
-P | Set the directory prefix where downloaded files are saved |
--limit-rate | Cap download bandwidth, e.g. --limit-rate=200k |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (not preinstalled; install via Homebrew)
What it does
wget is a non-interactive network downloader that retrieves files over HTTP, HTTPS,
and FTP. "Non-interactive" is the key word: it's designed to run unattended in scripts,
cron jobs, and background processes, with built-in support for retries, resuming
partial downloads, and recursively following links to mirror entire sites or directory
trees.
Beginner examples
wget https://example.com/file.zip— download a file, saving it with its original name in the current directorywget -O myfile.zip https://example.com/file.zip— download and save under a custom filenamewget -c https://example.com/bigfile.iso— resume a download that was interruptedwget -q https://example.com/file.zip— download quietly, without progress output
wget https://releases.example.com/app-1.2.0.tar.gz
Advanced examples
- Recursively mirror a site or directory:
wget -r -np -k https://example.com/docs/ - Save downloads into a specific directory:
wget -P ~/Downloads https://example.com/file.zip - Send a download to the background so it survives closing the terminal:
wget -b https://example.com/large.iso - Throttle bandwidth so a big download doesn't saturate the connection:
wget --limit-rate=300k https://example.com/large.iso - Download a list of URLs from a text file:
wget -i urls.txt
wget -r -np -nH --cut-dirs=2 -P ./mirror https://example.com/data/reports/
Common mistakes
- Forgetting
-np(no-parent) when recursively downloading a subdirectory — without it,wget -rcan climb up and pull in unrelated parts of the site. - Re-running a plain
wget URLafter an interrupted download instead ofwget -c URL— without-cit starts over from scratch (or creates afile.1duplicate) instead of resuming. - Assuming
-bshows live progress in the terminal — backgrounded downloads redirect their output towget-log, so you need totail -f wget-logto watch progress. - Not realizing some servers don't support byte-range requests, which means
-ccan't actually resume and will re-download from the start regardless.
Tips
- Use
wget --spider URLto check whether a URL exists and is reachable without actually downloading it — handy in monitoring scripts. - Combine
-cwith-bfor large, unreliable downloads: it backgrounds the job and will resume cleanly if you rerun the same command later. wget -i urls.txtreads one URL per line from a file, useful for batch-downloading many files in one command.
Best practices
- Always use
-np(and often-nH --cut-dirs) when mirroring a subdirectory so you don't accidentally pull the entire remote site. - Rate-limit large or repeated automated downloads with
--limit-rateto avoid overwhelming shared networks or triggering abuse detection on the remote server. - Prefer HTTPS URLs and let wget verify certificates by default; only pass
--no-check-certificateas a deliberate, documented exception, never as a habit.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Downloading release artifacts or installers in a CI/CD pipeline or Dockerfile build step.
- Mirroring documentation or datasets from a public directory listing for offline use.
- Resuming a multi-gigabyte ISO or dataset download over an unreliable connection without starting from zero each time it drops.
Common interview questions
- When would you choose wget over curl? When you need straightforward file downloading with built-in recursive mirroring and resume support and don't need curl's broader protocol/API-scripting features; wget's defaults are more download-oriented out of the box.
- How does wget resume a partial download? With
-c, it checks the existing local file's size and issues an HTTP Range request asking the server for only the remaining bytes, provided the server honors range requests. - How do you keep a long-running wget job alive after logging out of an SSH
session? Use
wget -b URLto background it immediately, or run it undernohup ... &or inside atmux/screensession.
Frequently Asked Questions
What's the difference between wget and curl?
wget is built for downloading files and recursively mirroring sites, and it works well non-interactively with retries and resuming out of the box. curl is a more general-purpose data-transfer tool that supports more protocols and is often preferred for scripting API calls, but downloading a single file with -O works similarly in both.
How do I resume an interrupted download?
Run wget -c URL again with the same output filename; it detects the partial file and requests only the remaining bytes via an HTTP Range request, provided the server supports it.
How do I download a whole website or directory listing?
wget -r -np -k URL recursively downloads linked pages/files, -np keeps it from ascending to the parent directory, and -k rewrites links for local browsing.
How can I run a large download without it dying when I close my terminal?
Use wget -b URL to send it to the background immediately (writing progress to wget-log), or wrap it in nohup wget URL & so it survives terminal disconnection.
Cheat sheet
Download a quick-reference cheat sheet for wget.