wget — Downloading Files from the Command Line¶
wget (Web Get) is a powerful command-line utility used to download files from web servers using HTTP, HTTPS, and FTP. It is designed for reliable, non-interactive downloading, making it ideal for automation, scripts, software installation, backups, and mirroring websites. Linux administrators, DevOps engineers, Cloud Architects, and Site Reliability Engineers (SREs) frequently use
wgetto retrieve files and automate downloads.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand the
wgetcommand - Download files from the Internet
- Resume interrupted downloads
- Download files in the background
- Mirror websites
- Authenticate downloads
- Automate file downloads
- Troubleshoot download issues
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management
- Module 5 – Users and Groups
- Module 6 – Process Management
- Module 7 – Package Management
- Module 8 Lessons 1–9
Why Learn wget?¶
Imagine:
- Downloading an ISO image.
- Fetching application binaries.
- Downloading backup files.
- Mirroring a documentation website.
- Automating software installation.
wget is the preferred tool for these tasks because it is reliable and script-friendly.
What is wget?¶
wget stands for:
It is a non-interactive download utility that supports:
- HTTP
- HTTPS
- FTP
It is commonly used for:
- Downloading files
- Automation scripts
- Software installation
- Website mirroring
- Scheduled downloads
How wget Works¶
Basic Download¶
Download a file.
The file is saved using its original filename.
Save with a Different Name¶
Resume an Interrupted Download¶
The -c option resumes downloading from where it stopped.
Download in the Background¶
Check the log:
Limit Download Speed¶
Useful when sharing network bandwidth.
Download Multiple Files¶
Create a file named urls.txt:
Download all files.
Mirror a Website¶
Commonly used for:
- Documentation
- Static websites
- Offline browsing
Recursive Download¶
Downloads linked content recursively.
Download Without Parent Directories¶
The -np option prevents ascending to parent directories.
Download with Authentication¶
Basic Authentication:
Avoid placing passwords directly on the command line in shared or production environments because they may be visible in process listings.
Ignore Certificate Validation¶
Warning: Use this only for testing. It disables TLS certificate validation and should not be used in production.
Continue Existing Downloads¶
If a file already exists:
This prevents restarting large downloads from the beginning.
Common Commands¶
Basic download.
Resume download.
Background download.
Mirror website.
Download list of files.
Real Production Examples¶
Download Kubernetes CLI.
Download Terraform.
Download an application backup.
Mirror documentation.
Production Perspective¶
wget is commonly used for:
- Software deployment
- CI/CD pipelines
- Backup retrieval
- Infrastructure automation
- Cloud provisioning
- Configuration downloads
- Offline documentation
- Scheduled maintenance
It is a reliable tool for unattended downloads in production environments.
Hands-on Lab¶
Task 1¶
Download a web page.
Task 2¶
Save the file with a custom name.
Task 3¶
Resume a download.
Task 4¶
Download in the background.
Monitor progress.
Task 5¶
Create a download list.
Download all files.
Task 6¶
Limit download speed.
Task 7¶
Mirror a website.
Task 8¶
Download recursively.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
wget URL | Download file | Software installation |
wget -O | Save with custom filename | Backup download |
wget -c | Resume download | Large ISO files |
wget -b | Background download | Automation |
wget -i | Download file list | Batch downloads |
wget --mirror | Mirror website | Documentation backup |
wget -r | Recursive download | Static website retrieval |
wget --limit-rate | Limit bandwidth | Shared networks |
wget vs curl¶
| Feature | wget | curl |
|---|---|---|
| Download Files | ✅ Excellent | ✅ |
| Resume Downloads | ✅ Excellent | Basic |
| Recursive Downloads | ✅ | ❌ |
| Website Mirroring | ✅ | ❌ |
| REST API Testing | Limited | ✅ Excellent |
| Multiple HTTP Methods | Limited | ✅ |
Use:
- wget for downloading files and websites.
- curl for APIs, HTTP requests, and web service testing.
Common wget Errors¶
| Error | Possible Cause |
|---|---|
Unable to resolve host | DNS problem |
Connection refused | Service unavailable |
404 Not Found | File does not exist |
403 Forbidden | Access denied |
SSL certificate error | Certificate validation failed |
Connection timed out | Network or firewall issue |
Production Troubleshooting Scenario¶
Scenario
A CI/CD pipeline fails while downloading a deployment package.
Command:
Error:
Investigation:
Verify DNS.
Check DNS resolution.
After correcting the DNS configuration:
The package downloads successfully, allowing the deployment to continue.
Best Practices¶
- Use
-cwhen downloading large files. - Use
-Oto save files with meaningful names. - Use
-bfor long-running downloads. - Limit download speed when sharing bandwidth.
- Verify downloaded files using checksums when available.
- Avoid exposing credentials on the command line.
- Use HTTPS whenever possible.
Common Mistakes¶
❌ Restarting large downloads instead of resuming them.
✅ Prefer resuming them rather than restarting large downloads.
❌ Downloading files without verifying their integrity.
✅ Avoid this mistake: downloading files without verifying their integrity.
❌ Using --no-check-certificate in production.
✅ Avoid using --no-check-certificate in production when a safer approach exists.
❌ Storing passwords directly in scripts.
✅ Avoid this mistake: storing passwords directly in scripts.
Interview Questions¶
Beginner¶
- What is
wgetused for? - How do you resume an interrupted download?
- Which option saves a file with a custom name?
- How do you download files in the background?
Intermediate¶
- What is the difference between
wgetandcurl? - How do you mirror a website?
- How do you download multiple files using
wget? - How do you limit download speed?
Architect Level¶
- How would you automate software downloads in a CI/CD pipeline?
- Why is
wgetpreferred for unattended downloads? - How would you securely download software packages in production?
Summary¶
In this lesson, you learned:
- The
wgetcommand - Downloading files
- Background downloads
- Resuming interrupted downloads
- Recursive downloads
- Website mirroring
- Authentication
- Production download automation
wget is one of the most reliable tools for downloading files in Linux. Its ability to resume downloads, work in the background, and automate file retrieval makes it indispensable for system administration, DevOps workflows, and infrastructure automation.
Key Takeaways¶
wgetis optimized for downloading files.- Use
-cto resume interrupted downloads. - Use
-Oto save files with custom names. - Use
-bfor background downloads. - Use
--mirrorto mirror websites. - Use
wgetfor unattended and automated download tasks.
What's Next?¶
SSH (Secure Shell) — Secure Remote Access to Linux Systems
You'll explore:
- Secure remote login
- SSH architecture
- SSH client and server
- Authentication methods
- SSH configuration
- Port forwarding
- Production security best practices
SSH is one of the most important tools for securely managing Linux systems remotely.