wget — Download Files and Websites

Practical guide to wget — file downloads, recursive retrieval, website mirroring and authentication on the command line, with examples for every use case.

wget is the go-to non-interactive downloader for the command line: a single command fetches individual files, recursive directory trees, or entire websites – reliably, even on slow or unreliable connections. It supports HTTP, HTTPS and FTP, resumes interrupted downloads without data loss, and respects servers through configurable wait times. This guide walks you through the most important options, from a simple file download to a full website mirror.

Basic Download

wget <url> — Download a file from the given URL to the current directory.

wget https://example.com/file.tar.gz

wget -O <file> <url> — Download and save with a specific filename.

wget -O output.html https://www.example.com

wget -P <directory> <url> — Download and save to a specific directory.

wget -P /tmp/ https://example.com/file.tar.gz

wget -q <url> — Quiet mode. Suppress output messages.

wget -q https://example.com/file.tar.gz

wget -i <file> — Download URLs listed in a text file (one per line).

wget -i urls.txt

Resume & Retry

wget -c <url> — Continue an interrupted download.

wget -c https://example.com/largefile.iso

wget -t <num> <url> — Set the number of retry attempts (0 for infinite).

wget -t 3 https://example.com/file.tar.gz

wget --timeout=<seconds> <url> — Set the network timeout in seconds.

wget --timeout=30 https://example.com/file.tar.gz

wget --waitretry=<seconds> <url> — Wait between retries, increasing with each attempt.

wget --waitretry=5 https://example.com/file.tar.gz

Recursive Download

wget -r <url> — Download recursively, following links up to 5 levels deep.

wget -r https://example.com/docs/

wget -r -l <depth> <url> — Recursive download with a custom depth limit.

wget -r -l 2 https://example.com/docs/

wget -r -np <url> — Recursive download without ascending to the parent directory.

wget -r -np https://example.com/docs/

wget -r -A "<extensions>" <url> — Download only files matching specific extensions.

wget -r -A "*.pdf,*.doc" https://example.com/docs/

wget -r -R "<extensions>" <url> — Reject files matching specific extensions.

wget -r -R "*.gif,*.jpg" https://example.com/docs/

Mirroring

wget -m <url> — Mirror a website (recursive, timestamping, infinite depth).

wget -m https://example.com/

wget -m -k -p <url> — Mirror a site and convert links for offline viewing.

wget -m -k -p https://example.com/

wget -m -k -p -E <url> — Mirror with adjusted file extensions (.html for all pages).

wget -m -k -p -E https://example.com/

wget --mirror --convert-links --wait=2 <url> — Mirror a site with a polite 2-second delay between requests.

wget --mirror --convert-links --wait=2 https://example.com/

Authentication

wget --user=<user> --password=<pass> <url> — Download with HTTP basic authentication.

wget --user=admin --password=secret https://example.com/private/

wget --header="Authorization: Bearer <token>" <url> — Download with a Bearer token.

wget --header="Authorization: Bearer eyJhbGci..." https://api.example.com/data

wget --no-check-certificate <url> — Skip SSL certificate verification (insecure, for testing only).

wget --no-check-certificate https://self-signed.example.com/file

Speed & Bandwidth

wget --limit-rate=<rate> <url> — Limit download speed to a specific rate.

wget --limit-rate=500k https://example.com/largefile.iso

wget -b <url> — Download in the background. Output goes to wget-log.

wget -b https://example.com/largefile.iso

wget --wait=<seconds> -r <url> — Wait between retrievals during recursive downloads.

wget --wait=2 -r https://example.com/docs/

wget --random-wait -r <url> — Wait a random time (0.5x to 1.5x --wait) between requests.

wget --wait=3 --random-wait -r https://example.com/

Output Options

wget -O - <url> — Download and print to stdout instead of a file.

wget -O - https://api.example.com/data

wget --spider <url> — Check if a URL exists without downloading (like a ping).

wget --spider https://www.example.com

wget -S <url> — Print server response headers.

wget -S https://www.example.com

wget --content-disposition <url> — Use the server-suggested filename from Content-Disposition header.

wget --content-disposition https://example.com/download?id=123

Conclusion

wget is a classic in the Unix toolkit: while cURL shines for sending and receiving API data, wget is unbeatable for robust batch downloads, site mirroring, and automated scripts. If you regularly pull large amounts of data from servers, make --limit-rate, --wait, and -c your first go-to options.

Further Reading

  • curl – HTTP requests, API calls and file transfers on the command line
  • aria2 – fast parallel downloader for large files
  • httpie – modern, user-friendly HTTP client