Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Wget command in Linux

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to use Wget commands in Linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Wget commands in Linux" this article.

Wget is a command line utility for downloading files from Web. With Wget, you can download files using the HTTP,HTTPS and FTP protocols. Wget provides many options that allow you to download multiple files, resume downloads, limit bandwidth, recursive downloads, download in the background, mirror sites, and so on.

1. Download a single file using wget

The following example is to download a file from the network and save it in the current directory

Wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zipwget-P / tools http://cn.wordpress.org/wordpress-3.1-zh_CN.zip

-P specifies which directory to download to

A progress bar is displayed during the download process, including (percentage of download completed, bytes already downloaded, current download speed, remaining download time).

2. Use wget-O to download and save under a different file name.

By default, wget commands with the last character following the "/", and the file name is usually incorrect for dynamically linked downloads. Error: the following example downloads a file and saves it with the name download.php?id=1080

Wget https://www.centos.bz/download?id=1

Even if the downloaded file is in zip format, it still uses the download.php?id=1080 command. Correct: to solve this problem, we can use the parameter-O to specify a file name:

Wget-O wordpress.zip https://www.centos.bz/download.php?id=10803, download speed limit using wget-limit-rate

When you execute wget, it takes up all possible broadband downloads by default. But the speed limit is necessary when you are ready to download a large file and you need to download other files.

Wget-limit-rate=300k http://cn.wordpress.org/wordpress-3.1-zh_CN.zip4, resume transmission using wget-c breakpoint

Restart the download interrupted file using wget-c:

Wget-c http://cn.wordpress.org/wordpress-3.1-zh_CN.zip

It is very helpful for us to download large files when we are suddenly interrupted due to network and other reasons, we can continue to download instead of downloading a file. You can use the-c parameter when you need to continue interrupting downloads.

5. Use wget-b to download in the background

For downloading very large files, we can use the parameter-b for background download.

Wget- b http://cn.wordpress.org/wordpress-3.1-zh_CN.zipContinuing in background, pid 1840.Output will be written to `wget-log'.

You can use the following command to check the download progress

Download tail-f wget-log6, camouflage agent name

Some websites can reject your download request by judging that the proxy name is not a browser. However, you can disguise it with the-user-agent parameter.

Wget-user-agent= "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16" download link 7, use wget-spider test download link

When you plan to download regularly, you should test whether the download link is valid at the scheduled time. We can add the-spider parameter to check.

Wget-spider URL

If the download link is correct, it will display

Wget-spider URLSpider mode enabled. Check if remote file exists.HTTP request sent, awaiting response... 200 OKLength: unspecified [text/html] Remote file exists and could contain further links,but recursion is disabled-not retrieving.

This ensures that the download will take place at the scheduled time, but when you give the wrong link, the following error will be displayed

Wget-spider urlSpider mode enabled. Check if remote file exists.HTTP request sent, awaiting response... 404 Not FoundRemote file does not exist-broken Linklinks!

You can use the spider parameter in the following situations:

Check the interval before regular download to check whether the website is available to check the dead links on the page of the website 8. Use wget-tries to increase the number of retries

If there is a problem with the network or downloading a large file may also fail. By default, wget retries the connection to download the file 20 times. If necessary, you can use-tries to increase the number of retries.

Wget-tries=40 URL9, download multiple files using wget-I

First, save a download link file

Cat > filelist.txturl1url2url3url4

Then use this file and parameters-I to download

Wget-I filelist.txt10, using wget-mirror mirroring website

The following example is to download the entire site locally.

Wget-mirror-p-convert-links-P. / LOCAL URL-miror: account opening image download-p: download all files that are displayed normally for the html page-convert-links: after download, convert to local link-P. / LOCAL: save all files and directories to the local specified directory 11, use wget-reject to filter the specified format for download

You want to download a website, but you do not want to download pictures, you can use the following command.

Wget-reject=gif url12, use wget-o to save download information to log file

You do not want the download information to be displayed directly on the terminal but in a log file, you can use the following command:

Wget-o download.log URL13, use wget-Q to limit the total download file size

When you want to download more than 5m files and exit the download, you can use the following command:

Wget-Q5m-I filelist.txt

Note: this parameter does not work for a single file download and is only valid for recursive downloads.

14. Use wget-r-A to download files in the specified format

You can use this feature in the following situations

Download all the pictures of a website download all the videos of a website download all the PDF files of a website wget-r-A.pdf url15, download using wget FTP

You can use wget to download the ftp link. Download using wget anonymous ftp

Wget ftp-url

Ftp downloads authenticated with wget username and password

Wget-ftp-user=USERNAME-ftp-password=PASSWORD url

The above is all the contents of the article "how to use Wget commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report