wget
wget is a command-line tool for downloading files. It supports HTTP, HTTPS, and FTP, and handles recursive downloads and background execution.
Syntax
Run a basic download.
wget URL
Save with a specific filename.
wget -O output-filename URL
Specify a destination directory.
wget -P target-directory URL
Download in the background.
wget -b URL
Recursively download (mirror an entire site).
wget -r URL
Run in quiet mode (no progress output).
wget -q URL
Options
| Option | Description |
|---|---|
| -O file | Specifies the filename to save the download as. |
| -P directory | Specifies the directory to save the downloaded file in. |
| -q | Runs in quiet (silent) mode — suppresses progress and messages. |
| -v | Shows verbose output (default behavior). |
| -b | Runs the download in the background. |
| -c | Resumes an interrupted download. |
| -r | Downloads recursively. |
| -l depth | Sets the recursion depth for recursive downloads (use with -r). |
| -np | Prevents ascending to the parent directory during recursive downloads (use with -r). |
| -A extension | Filters downloads by file extension. |
| --limit-rate=rate | Limits the download speed (e.g., 1m for 1 MB/s). |
| --tries=count | Sets the number of retry attempts on failure. |
| --timeout=seconds | Sets the connection timeout in seconds. |
| -i file | Reads a list of URLs from a text file and downloads them all. |
| --user-agent=string | Specifies the User-Agent string to use. |
Sample Code
Download a file. By default, wget shows detailed progress output.
wget https://example.com/file.txt --2026-03-06 12:00:00-- https://example.com/file.txt 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: 1024 (1.0K) [text/plain] Saving to: 'file.txt' file.txt 100%[===================>] 1.00K --.-KB/s in 0s 2026-03-06 12:00:01 (10.0 MB/s) - 'file.txt' saved [1024/1024]
Save the downloaded file under a specific name.
wget -O /tmp/archive.tar.gz https://example.com/release-1.0.tar.gz
Download a file into a specific directory.
wget -P /opt/downloads https://example.com/file.zip
Download in the background with a speed limit.
wget -b --limit-rate=500k https://example.com/large-file.iso Continuing in background, pid 12345. Output will be written to 'wget-log'.
If a download was interrupted, use -c to resume from where it left off.
wget -c https://example.com/large-file.iso
Read a list of URLs from a file and download them all at once.
cat urls.txt https://example.com/file1.txt https://example.com/file2.txt https://example.com/file3.txt wget -i urls.txt -P downloads/
Recursively download only images from a site, up to 2 levels deep.
wget -r -l 2 -A jpg,png -np https://example.com/gallery/
When using wget in a script, add -q (quiet) to suppress output and check the exit code for error handling.
download.sh
wget -q -O /tmp/data.json https://api.example.com/data
echo "Exit code: $?"
bash download.sh
Exit code: 0
Notes
wget excels at resuming interrupted downloads with the -c option, making it well-suited for large file downloads. Combining -r (recursive) with -A (extension filter) lets you batch-download only specific file types from a site.
When embedding wget in scripts, use -q (quiet) to suppress log output and check the exit code ($?) to detect errors. If you need fine-grained control over HTTP requests, consider using curl instead.
If you find any errors or copyright issues, please contact us.