Linux wget is a tool for downloading files. It is used in the command line. Linux users are essential tools. Especially for network administrators, you often need to download software or restore the backup from a remote server to a local server. If we use a VM, we can only download the transaction from the remote server to our computer disk, and then upload it to the server using FTP. This is a waste of time and energy. In Linux VPs, it can be directly downloaded to the server without uploading this step. Wget is a small tool with complete functions. It supports resumable download and FTP and HTTP download modes. It supports proxy servers and easy configuration. The following describes how to use wget in the form of an instance.
1. Use wget to download a single file
The following example downloads an object from the network and stores it in the current directory.
| Wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip |
The progress bar is displayed during the download process, including (download completion percentage, downloaded bytes, current download speed, and remaining download time ).
2. Use wget-O to download and save it with different file names
By default, wget uses the last character that matches the slash (/). For dynamic link download, the file name is usually incorrect. Error: The following example downloads an object and uses the name download. php? Save id = 1080
Wget http://www.zhumaohai.com/download? Id = 1 |
Even if the downloaded file is in ZIP format, it still uses download. php? Id = 1080 command. Correct: To solve this problem, we can use the-O parameter to specify a file name:
Wget-O wordpress.zip http://www.zhumaohai.com/download.php? Id = 1080 |
3. Use wget -- limit-rate to speed up download
When you execute wget, it will use all possible bandwidth downloads by default. However, when you are preparing to download a large file and you need to download other files, it is necessary to limit the speed.
Wget -- limit-rate = 300 K http://cn.wordpress.org/wordpress-3.1-zh_CN.zip |
4. Use wget-C for resumable Data Transfer
Use wget-C to restart the interrupted download file:
Http://cn.wordpress.org/wordpress-3.1-zh_CN.zip wget-C |
It is very helpful for us to suddenly interrupt the network when downloading large files. We can continue to download the files instead of downloading them again. You can use the-C parameter to continue interrupted downloads.
5. Use wget-B for background download
When downloading a very large file, we can use parameter-B for background download.
Http://cn.wordpress.org/wordpress-3.1-zh_CN.zip wget-B Continuing in background, PID 1840. Output will be written to 'wget-log '. |
You can use the following command to view the download progress
6. Download disguised proxy name
Some websites can reject your download requests by judging that the proxy name is not a browser. However, you can pretend to be using 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 to test the download link.
When you plan to perform regular download, you should test whether the download link is valid at the specified time. We can add the -- spider parameter for check.
If the download link is correct
Wget -- spider URL Spider Mode Enabled. Check if remote file exists. HTTP request sent, awaiting response. 200 OK length: unspecified [text/html] remote file exists and coshould contain further links, but recursion is disabled -- not retrieving. |
This ensures that the download can be performed at the specified time. However, when you send a wrong link, the following error will be displayed:
Wget -- spider URL Spider mode enabled. Check if remote file exists. http request sent, awaiting response... 404 Not found remote file does not exist -- Broken Link !!! |
You can use the spider parameter in the following situations:
7.1 check before scheduled download
7.2 Interval check whether the website is available
7.3 check dead links on the website page
8. Use wget -- tries to increase the number of retries
If the network is faulty or a large file is downloaded, it may fail. By default, wget retries 20 times to download files. If needed, you can use -- tries to increase the number of retries.
9. Use wget-I to download multiple files
First, save a download link file.
Cat> filelist.txt url1 url2 url3 url4 |
Use this file and the parameter-I to download it.
10. Use wget -- mirror to mirror the website
The following example downloads the entire website to a local device.
Wget -- mirror-p -- convert-links-P./local URL |
-- Miror: Download the Account Opening Image
-P: download all the files normally displayed for the HTML page.
-- Convert-links: Link to the local conversion cost after download
-P./local: Save all files and directories to the specified local directory.
11. Use wget -- reject to filter download in the specified format
You want to download a website, but you do not want to download images, you can use the following command.
12. Use wget-O to save the downloaded information to the log file.
You do not want to download information directly displayed on the terminal but in a log file. You can use the following command:
13. Use wget-Q to limit the total size of downloaded files
If you want to download an object that exceeds 5 MB and exit the download process, run the following command:
Note: This parameter does not work for downloading a single object and is only valid for Recursive download.
14. Use wget-r-a to download a file in the specified format
You can use this function in the following situations:
Download all images of a website
Download all videos from a website
Download all PDF files from a website
15. Use wget FTP to download
You can use wget to download the FTP link. Use wget for anonymous FTP download
Download FTP with wget user name and password authentication
Wget -- FTP-user = username -- FTP-Password = PASSWORD URL |
Source: http://www.zhumaohai.com/reprinted Please retain copyright