Linux wget command
What is the wget command?
wget is a powerful non-interactive network download tool in Linux; its name comes from the combination of "World Wide Web" and "get". It supports downloading files via HTTP, HTTPS, and FTP, with useful features such as resuming interrupted downloads and recursive downloading.
Unlike browser downloads or the curl command, the main features of wget are:
- Non-interactive: can run in the background without user intervention
- High stability: automatically retries when the network fluctuates
- Feature-rich: supports a variety of download scenarios and advanced options
Basic wget syntax
wget [选项] [URL]
The simplest download example
Example
wget
https:
//
example.com
/
file.zip
This command downloads the file at the specified URL to the current directory.
Detailed explanation of common options
Download control options
| Option | Description | Example |
|---|---|---|
-O <文件名> |
Specify the saved file name | wget -O myfile.zip https://example.com/file.zip |
-P <目录> |
Specify the download directory | wget -P ~/downloads https://example.com/file.zip |
-c |
Resume interrupted downloads | wget -c https://example.com/bigfile.iso |
-b |
Background download | wget -b https://example.com/largefile.mp4 |
Connection settings options
| Option | Description | Example |
|---|---|---|
--limit-rate=<速度> |
Limit download speed | wget --limit-rate=200k https://example.com/file.iso |
-t <次数> |
Set the number of retries | wget -t 5 https://example.com/unstable.file |
--timeout=<秒> |
Set the timeout | wget --timeout=30 https://example.com/slow.file |
Recursive download options
| Option | Description | Example |
|---|---|---|
-r |
Recursive download | wget -r https://example.com/directory/ |
-l <深度> |
Set the recursion depth | wget -r -l 2 https://example.com/ |
-np |
Do not ascend to parent directories | wget -r -np https://example.com/path/ |
Practical examples and application scenarios
Example 1: download a single file and rename it
Example
wget
-O
linux_distro.iso https:
//
example.com
/
ubuntu-
22.04
.iso
Description:
- Download the Ubuntu 22.04 image from the specified URL
- Use
-Ooption saves the file with a custom namelinux_distro.iso
Example 2: download a large file with a speed limit
Example
wget
--limit-rate
=500k
-c
https:
//
example.com
/
large_video.mp4
Description:
--limit-rate=500kLimit the download speed to 500KB/s-csupports resuming interrupted downloads, so downloading can continue after a network interruption
Example 3: recursively download an entire website
Example
wget
-r
-l
5
--convert-links
--wait
=
2
https:
//
example-site.com
Description:
-rEnable recursive download-l 5Set the maximum recursion depth to 5 levels--convert-linksConvert links for local browsing--wait=2Wait 2 seconds between downloads to reduce the load on the server
Advanced tips and precautions
1. Download files in bulk
Create a text file containing multiple URLs urls.txt, then use:
Example
wget
-i
urls.txt
2. Download FTP resources
Example
wget
ftp:
//
username:password
@
ftp.example.com
/
file.zip
Note: the password will appear in the command history; it is recommended to use the --ftp-user and --ftp-password option to set it separately.
3. Troubleshooting common problems
Problem 1: certificate errors
Example
wget
--no-check-certificate
https:
//
example.com
Problem 2: download denied (403 Forbidden)
Example
wget
--user-agent
=
"Mozilla/5.0"
https:
//
example.com
Visualization: wget workflow

Practical Exercise
-
Try downloading the Linux kernel source:
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.5.tar.xz 2.
Use resume to download a large file; after an interruption, reconnect and continue downloading
3.Create a text file with multiple image URLs and use the batch download feature to fetch all the images
Summary
wget is an indispensable download tool in Linux. Through this article you have learned:
- wget's basic syntax and common options
- download methods in various practical application scenarios
- advanced tips and problem solutions
- how to implement recursive and batch downloads
Mastering the wget command will greatly improve your efficiency in handling network resources in a Linux environment.
Linux Command Reference