wget Command in Linux — Download Files with Examples
The wget command downloads files from the internet in Linux — supporting HTTP, HTTPS, and FTP protocols, recursive downloads, resume capabilities, and bandwidth throttling. It’s the go-to tool for downloading files, mirroring websites, and automating data retrieval in scripts.
What You’ll Learn
You’ll master single-file downloads, recursive site fetching, resuming broken transfers, mirroring websites, limiting bandwidth, and scripting automated downloads with wget.
Why wget Matters
Server administration requires downloading files — software packages, backups, security patches — often through unreliable connections or over slow links. wget handles interruptions gracefully with automatic resume. DodaZIP uses wget to fetch daily definition updates, and Durga Antivirus Pro downloads threat signature databases on schedule using wget cron jobs.
Learning Path
flowchart LR
A[Linux Basics] --> B[Networking Commands]
B --> C[wget Command<br/>You are here]
C --> D[curl Command]
C --> E[Scripting Automation]
style C fill:#f90,color:#fff
Syntax Overview
wget [options] [URL...]Options Table
| Option | Description |
|---|---|
-O file | Save output to a specific filename |
-c | Resume an interrupted download |
-r | Recursive download |
-m | Mirror a website (equivalent to -r -N -l inf) |
-np | No parent directory traversal |
-nH | No hostname prefix in saved paths |
--limit-rate=RATE | Limit download speed (e.g., 200k, 1m) |
-q | Quiet mode (no output) |
-b | Background mode |
--tries=N | Number of retry attempts |
--wait=SEC | Wait between downloads |
-P DIR | Save files to directory prefix |
-N | Timestamp-based download (only if newer) |
Examples
Example 1: Download a Single File
$ wget https://example.com/file.zip
--2026-06-20 10:00:00-- https://example.com/file.zip
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com (example.com)|93.184.216.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1048576 (1.0M) [application/zip]
Saving to: 'file.zip'
file.zip 100%[=====================>] 1.00M 5.2MB/s in 0.2sThe simplest use case — one command, file saved with its original name.
Example 2: Save As Different Name (-O)
$ wget -O myapp-latest.tar.gz https://example.com/downloads/app-v3.2.1.tar.gzUseful when URLs don’t end with the filename you want.
Example 3: Resume Interrupted Download (-c)
$ wget -c https://example.com/large-file.iso
--2026-06-20 10:05:00-- https://example.com/large-file.iso
Resuming from byte position 52428800.
Length: 104857600 (100M), 52428800 (50M) remaining-c continues from where the previous attempt stopped — essential for large files on unstable connections.
Example 4: Recursive Download (-r)
$ wget -r -l2 -np https://example.com/docs/Downloads all files from /docs/ up to 2 levels deep, without ascending to the parent directory.
Example 5: Mirror a Website (-m)
$ wget -m -np -nH --cut-dirs=1 https://example.com/tutorials/Creates a complete local mirror suitable for offline browsing. Combine with -np to stay within the site.
Example 6: No Parent (-np)
$ wget -r -np https://example.com/downloads/Without -np, wget would crawl the entire site. -np restricts to the specified directory and its children.
Example 7: Limit Download Rate (–limit-rate)
$ wget --limit-rate=200k https://example.com/huge-file.isoPrevents wget from saturating the bandwidth — important on production servers that share network resources.
Example 8: Quiet Mode (-q)
$ wget -q -O /dev/null https://example.com/healthcheck
# In scripts, check exit code:
if wget -q --spider https://example.com; then
echo "Site is up"
fi--spider checks if a URL exists without downloading. Use in monitoring scripts.
Example 9: Retry with Backoff
$ wget --tries=10 --retry-connrefused --wait=5 https://example.com/unstable-server/data.csvRetries up to 10 times, with a 5-second wait between attempts.
Example 10: FTP Download
$ wget --user=anonymous --password=guest ftp://ftp.example.com/pub/READMEwget supports FTP with authentication. Anonymous FTP is common for public archives.
Common Use Cases
| Use Case | Command |
|---|---|
| Download a single file | wget https://url/file |
| Download with resume | wget -c https://url/large-file |
| Mirror a website | wget -m -np -nH https://site.com/ |
| Speed-limited download | wget --limit-rate=500k https://url/file |
| Download in background | wget -b https://url/file |
| Check URL exists | wget --spider https://url |
| Recursive with depth | wget -r -l3 https://site.com/docs/ |
Common Errors
- Connection refused: The server is down or blocking your IP. Check firewall rules.
- 404 Not Found: The URL is incorrect or the file moved. Verify the path.
- Permission denied on FTP: Wrong credentials or the server doesn’t allow anonymous access.
- Certificate warnings: Use
--no-check-certificateONLY for testing — never in production scripts. - wget: command not found: Install with
apt install wgetoryum install wget. - Resume not possible: The server doesn’t support
Rangeheaders. Some CDNs block range requests.
Practice Exercises
- Basic download: Download the Debian netinstall ISO (you can cancel after a few MB).
- Resume: Start a download, cancel with Ctrl+C, then resume with
-c. - Mirror: Mirror a small documentation site to your local machine.
- Limit rate: Download a file at 100KB/s and observe the speed.
- Script a download: Write a script that downloads a file, retries on failure, and logs the result.
Challenge
Write a cron-compatible script that downloads the latest threat definitions for Durga Antivirus Pro every hour, saves with a timestamp, and deletes files older than 7 days. Include retry logic and logging.
#!/bin/bash
URL="https://definitions.durga-av.example.com/latest.dat"
DEST="/var/durga/definitions/$(date +%Y%m%d-%H%M%S).dat"
LOG="/var/log/durga-updates.log"
wget -q -O "$DEST" "$URL" --tries=3 --timeout=30 && \
echo "$(date): Downloaded $DEST" >> "$LOG" || \
echo "$(date): FAILED" >> "$LOG"
# Cleanup files older than 7 days
find /var/durga/definitions/ -name "*.dat" -mtime +7 -deleteReal-World Task
Your web application server needs to download daily backups from a remote FTP server. Create a wget command that:
- Downloads only files newer than the local copy
- Limits speed to 1MB/s to avoid saturating the link
- Retries 5 times on failure
- Logs all activity to a file
Solution: wget -N --limit-rate=1m --tries=5 -a /var/log/backup-download.log ftp://backups.example.com/daily/
What is wget?
wget (Web Get) is a non-interactive download tool supporting HTTP, HTTPS, and FTP protocols — designed for reliable, resumable, and recursive downloads, ideal for scripting and automation.
Related Tutorials
- Essential Linux Commands — network tools overview
- Cron Job Scheduling — automate wget with cron
- Bash Scripting Guide — scripts that use wget
- Linux Administration Basics — foundational admin skills
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro