Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux wget command

Linux wget command

Linux Command Reference Linux Command Reference


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:


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:

Example 2: download a large file with a speed limit

Example

wget

--limit-rate

=500k

-c

https:

//

example.com

/

large_video.mp4

Description:

Example 3: recursively download an entire website

Example

wget

-r

-l

5

--convert-links

--wait

=

2

https:

//

example-site.com

Description:


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

  1. 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:

Mastering the wget command will greatly improve your efficiency in handling network resources in a Linux environment.

Linux Command Reference Linux Command Reference