# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/networking/wget/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Basic Download

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

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

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

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

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

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

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

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

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

```bash
wget -i urls.txt
```

## Resume & Retry

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

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

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

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

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

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

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

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

## Recursive Download

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

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

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

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

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

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

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

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

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

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

## Mirroring

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

```bash
wget -m https://example.com/
```

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

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

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

```bash
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.

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

## Authentication

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

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

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

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

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

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

## Speed & Bandwidth

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

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

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

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

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

```bash
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.

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

## Output Options

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

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

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

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

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

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

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

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

<!-- PROSE:outro -->
## 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

- [GNU Wget – official documentation](https://www.gnu.org/software/wget/manual/wget.html) – complete reference for all options
- [Wget – Wikipedia](https://en.wikipedia.org/wiki/Wget) – background and history
<!-- PROSE:outro:end -->

## Related Commands

- [curl](https://www.jpkc.com/db/en/cheatsheets/networking/curl/) – HTTP requests, API calls and file transfers on the command line
- [aria2](https://www.jpkc.com/db/en/cheatsheets/networking/aria2/) – fast parallel downloader for large files
- [httpie](https://www.jpkc.com/db/en/cheatsheets/networking/httpie/) – modern, user-friendly HTTP client

