Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

wget Command Guide for Downloading Files From the Web

wget downloads files from the web non-interactively — it follows links, resumes interrupted transfers, and can mirror an entire website to your disk.


What is wget, and Why Use It?

wget is a free utility for downloading content from the web over HTTP, HTTPS, FTP, and FTPS. Where curl is a general-purpose transfer tool you shape by hand, wget is purpose-built for downloading: give it a URL and it retrieves the file, retries on failure, and keeps going — no further input from you, ever.

That “never asks” behavior is the point. wget is the tool you reach for when a download must complete unattended: large files over flaky connections, whole directories of assets, or a cron job that fetches a report every night. It is preinstalled on most Linux systems and is a rite of passage for server administrators.

Why Learn wget?

  • Downloads that survive interruption — -c resumes a half-finished file, which matters for large downloads over unreliable links.
  • Mirroring whole sites — wget --mirror can pull an entire documentation site to your disk for offline reading.
  • Scripting workhorse — countless install scripts, CI pipelines, and tutorials download with wget; reading them assumes you know the flags.

wget never prompts. If a download would require interaction (a login form, a confirmation), wget cannot do it the way a browser can — use curl with headers, or a browser, for those.


1. Downloading a Single File

The core use — fetch a file:

wget https://example.com/files/manual.pdf
--2026-12-05 10:14:02--  https://example.com/files/manual.pdf
Resolving example.com... 93.184.216.34
Connecting to example.com|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21750 (21K) [application/pdf]
Saving to: 'manual.pdf'

manual.pdf          100%[===================>]  21.24K  --.-KB/s    in 0.004s

The file is saved with the name from the URL, in the current directory. Progress is printed live. If the file already exists, wget refuses to overwrite it by default — see the next section for what to do instead.

2. Naming Files and Resuming Downloads

Two flags cover most everyday needs:

wget -O my-name.pdf https://example.com/files/manual.pdf   # save under a name you choose
wget -c https://example.com/files/manual.pdf               # resume an interrupted download

-O (capital oh) writes to the file you name; -c continues from where a previous, incomplete attempt stopped. Together they make wget the right tool for big files: start it, let it fail if the connection drops, and rerun with -c until it finishes.

On the first run -c has nothing to resume, so it behaves like a normal download. That makes -c safe to add to any wget command “just in case”.

3. Backgrounding, Retries, and Limits

For downloads you do not want to babysit:

wget -b https://example.com/files/huge.iso        # run in the background, log to wget-log
wget -c -t 0 https://example.com/files/huge.iso   # retry forever until it completes
wget --limit-rate=500k https://example.com/file    # cap bandwidth at 500 KB/s

-b backgrounds the download and writes progress to a file called wget-log; -t 0 means “retry indefinitely” (default is 20 attempts); --limit-rate keeps wget from saturating your connection. To watch a background download:

tail -f wget-log

4. Downloading Whole Sites: Mirroring

The feature that makes wget unique is mirroring — downloading a site (or a directory of it) for offline use:

wget --mirror --convert-links --page-requisites \
  --no-parent https://example.com/docs/

What each part does:

  • --mirror — shorthand for recursion plus timestamping; follows links and downloads everything linked under the starting point.
  • --convert-links — rewrites links in downloaded HTML so the offline copy navigates locally.
  • --page-requisites — also fetches the images, stylesheets, and scripts each page needs.
  • --no-parent — never climb above the starting directory.

The result is a browsable local copy of the docs. Add --restrict-file-names=windows if you plan to open the copy on Windows machines.

Mirroring is polite only with limits. Add --wait=1 (one second between requests) or --warp-style throttling so you do not hammer a small server.

5. Authenticated and Conditional Downloads

Some files need credentials:

wget --user=alice --password=secret https://files.example.com/private/report.pdf

Or, more safely, from a netrc file so the password stays out of your shell history:

wget --http-user=alice --ask-password https://files.example.com/private/report.pdf

wget can also check whether a local copy is current before re-downloading — --timestamping compares the server’s last-modified date and only fetches when the file has changed. This is what you use in periodic sync scripts:

wget --timestamping --recursive --no-parent https://example.com/data/

6. Reading wget Output in Scripts

wget prints a lot, which is noisy in scripts. The common adjustments:

wget -q https://example.com/file        # quiet: no output at all
wget -q --spider https://example.com    # just check if the URL exists; exit code says which

--spider performs the download without saving anything and exits 0 if the URL is live, non-zero if not — the same trick as curl’s status-code check, and the standard way to test links in a script.


Common Pitfalls

  • Expecting browser behavior — wget cannot fill login forms, click buttons, or run JavaScript. When a “download” is actually a web app interaction, use the site’s direct file URL or a browser.
  • Letting -O overwrite important files — -O silently replaces the target file. Unlike a normal download, there is no “file exists” warning.
  • Mirroring without limits — an unthrottled --mirror can look like a denial-of-service attack to a small server; always add --wait or --limit-rate.
  • Assuming wget and curl are interchangeable — they overlap for simple downloads, but curl is the API/HTTP workhorse and wget is the bulk downloader. Scripts differ in which they need.
PageRelationship
curlThe general URL transfer tool — APIs, headers, and everything not-file-like
pingConfirms the host answers before you attempt a download
tracerouteLocates the broken hop when downloads stall mid-transfer
ncRaw connections for testing the server when downloads fail mysteriously

wget Cheatsheet

CommandWhat it does
wget URLDownload a file into the current directory
wget -O name URLSave under a filename you choose
wget -c URLResume an interrupted download
wget -b URLDownload in the background (logs to wget-log)
wget -t 0 URLRetry forever until the download completes
wget --limit-rate=500k URLCap download bandwidth
wget --mirror --convert-links --page-requisites --no-parent URLMirror a site section for offline use
wget --timestamping URLRe-download only if the server’s copy changed
wget -q --spider URLCheck a URL exists without downloading (script-friendly)
wget --user=U --ask-password URLDownload from a password-protected location