How to use the wget command under linux
Editor to share with you how to use the wget command under linux. I hope you will get something after reading this article. Let's discuss it together.
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.zip
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 http://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 http://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.zip
Continuing 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 before regular download
Interval to check whether a website is available
Check the dead links on the website page
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 on a website
Download all the videos on 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
After reading this article, wget-ftp-user=USERNAME-ftp-password=PASSWORD url, I believe you have a certain understanding of "how to use wget commands under linux". If you want to know more about it, please follow the industry information channel. Thank you for reading!