Skip to content
wget Command in Linux — Download Files with Examples

wget Command in Linux — Download Files with Examples

DodaTech Updated Jun 20, 2026 5 min read

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
  
Prerequisites: Internet access and basic essential Linux command knowledge. Works on any Linux distribution.

Syntax Overview

wget [options] [URL...]

Options Table

OptionDescription
-O fileSave output to a specific filename
-cResume an interrupted download
-rRecursive download
-mMirror a website (equivalent to -r -N -l inf)
-npNo parent directory traversal
-nHNo hostname prefix in saved paths
--limit-rate=RATELimit download speed (e.g., 200k, 1m)
-qQuiet mode (no output)
-bBackground mode
--tries=NNumber of retry attempts
--wait=SECWait between downloads
-P DIRSave files to directory prefix
-NTimestamp-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.2s

The 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.gz

Useful 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.iso

Prevents 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.csv

Retries 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/README

wget supports FTP with authentication. Anonymous FTP is common for public archives.

Common Use Cases

Use CaseCommand
Download a single filewget https://url/file
Download with resumewget -c https://url/large-file
Mirror a websitewget -m -np -nH https://site.com/
Speed-limited downloadwget --limit-rate=500k https://url/file
Download in backgroundwget -b https://url/file
Check URL existswget --spider https://url
Recursive with depthwget -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-certificate ONLY for testing — never in production scripts.
  • wget: command not found: Install with apt install wget or yum install wget.
  • Resume not possible: The server doesn’t support Range headers. Some CDNs block range requests.

Practice Exercises

  1. Basic download: Download the Debian netinstall ISO (you can cancel after a few MB).
  2. Resume: Start a download, cancel with Ctrl+C, then resume with -c.
  3. Mirror: Mirror a small documentation site to your local machine.
  4. Limit rate: Download a file at 100KB/s and observe the speed.
  5. 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 -delete

Real-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

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro