Master the wget Command: Download Files Effortlessly in Linux

Fetch files with the wget command, your go-to tool for reliable downloads!

What is the wget Command?

Think of the wget command as a dependable delivery service for files, fetching them from the internet via HTTP, HTTPS, or FTP. Unlike curl, which is versatile for data transfers, wget excels at downloading files and entire websites with minimal configuration.

Why wget is Essential

Single File Downloads

Retrieve files with a single command.

Website Mirroring

Download entire websites recursively.

Automation

Script bulk or scheduled downloads.

Syntax and Options

The wget command downloads files from the specified URL:

wget [options] URL
        

Key options:

  • -O: Specify the output file name.
  • -r: Enable recursive downloading for websites.
  • -c: Resume interrupted downloads.
  • -b: Run the download in the background.
  • --limit-rate: Restrict download speed (e.g., 100k).

Real-World Examples

1. Download a Single File

Fetch a file from a URL:

wget https://example.com/file.zip
        

Output: Downloads file.zip to the current directory, displaying a progress bar.

2. Specify Output File Name

Save a file with a custom name:

wget -O myfile.zip https://example.com/file.zip
        

Output: Saves the file as myfile.zip instead of the default name.

3. Resume an Interrupted Download

Continue a partial download:

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

Output: Resumes downloading largefile.iso from where it left off.

4. Mirror a Website

Download an entire website:

wget -r -l 1 https://example.com
        

Output: Downloads the website’s files up to one level deep into a local directory.

5. Limit Download Speed

Restrict bandwidth usage:

wget --limit-rate=100k https://example.com/file.zip
        

Output: Downloads file.zip at a maximum speed of 100 KB/s.

Advanced Usage

Take wget to the next level with these techniques:

  • Authenticated Downloads: Use --user and --password for protected resources.
  • Recursive Filtering: Use --accept or --reject to filter file types (e.g., *.pdf).
  • Background Downloads: Use -b to run downloads in the background and check wget-log.
  • Scheduled Downloads: Combine with cron for automated tasks.

Example: Download with authentication:

wget --user=username --password=pass https://example.com/protected/file.zip
        

Pro Tips

Automation: Use -b with cron for scheduled downloads.

Bandwidth Control: Always use --limit-rate on shared networks.

Mirroring: Use -m for full website mirroring with timestamps.

Common Mistakes to Avoid

Steer clear of these pitfalls when using wget:

  • Overwriting Files: Use -O to avoid overwriting existing files.
  • Unlimited Recursion: Set -l to limit recursive depth to avoid excessive downloads.
  • Ignoring Bandwidth: Use --limit-rate to prevent network strain.

Explore More Linux Commands

Master Linux with our expert guides!