Linux wget is a tool for downloading files, which is used at the command line. For Linux users is an essential tool, especially for network administrators, often to download some software or restore from the remote server back to the local server. If we use a virtual host, we can only download our computer disk from the remote server and upload it to the server using the FTP tool. This is a waste of time and energy, there is no way. And to the Linux VPS, it can be downloaded directly to the server without having to upload this step. wget tool Small but full-featured, it supports the breakpoint download, while supporting FTP and HTTP download mode, support proxy server and set up easy. Here we illustrate how to use wget in the form of an instance.
1. Download a single file using wget
The following example downloads a file from the network and saves it in the current directory
wget Http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
The progress bar will be displayed during the download, including the download percent complete, the bytes already downloaded, the current download speed, and the remaining download time.
2. Use Wget-o to download and save with different filename
wget defaults to the last character that matches the "/" command, and the download for dynamic links usually has incorrect file names.
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 is still in the download.php?id=1080 command.
Correct: To solve this problem, we can use parameter-o to specify a filename:
Wget-o Wordpress.zip http://www.centos.bz/download.php?id=1080
3. Use wget–limit-rate speed limit download
When you perform wget, it defaults to the full range of possible broadband downloads. But when you're ready to download a large file and you need to download other files, it's necessary to speed it down.
wget–limit-rate=300k Http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
4, the use of WGET-C breakpoint continued transmission
To restart a 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 suddenly because of interruptions such as network and so on, we can continue downloading instead of downloading a file again. You can use the-c parameter when you need to continue interrupting downloads.
5, the use of wget-b background download
For downloading very large files, we can use parameter-B for background downloading.
Wget-b Http://cn.wordpress.org/wordpress-3.1-zh_CN.zip
Continuing in background, PID 1840.
Output would be written to ' Wget-log '.
You can use the following command to view the download progress
Tail-f Wget-log
6, camouflage agent name Download
Some sites can reject your download request by judging that the proxy name is not a browser. But you can disguise it by –user-agent parameters.
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 do a timed download, you should test that the download link is valid at the scheduled time. We can increase the –spider parameters for inspection.
Wget–spider URL
If the download link is correct, it will display
Wget–spider URL
Spider mode enabled. Check if remote file exists.
HTTP request sent, awaiting response ... OK
length:unspecified [text/html]
Remote file exists and could contain further links,
But recursion is disabled-not retrieving.
This ensures that the download can be done at the scheduled time, but when you give 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:
Check before scheduled download
Interval detects whether a Web site is available
Check the dead link of the site page
8, use wget–tries to increase the number of retries
If there is a problem with the network or downloading a large file, it may fail. wget the connection download file by default retry 20 times. If necessary, you can use –tries to increase the number of retries.
Wget–tries=40 URL
9. Download multiple files using wget-i
First, save a copy of the download link file
Cat > Filelist.txt
Url1
Url2
Url3
Url4
Then use this file and parameter-I to download
Wget-i filelist.txt
10, use Wget–mirror Mirror website
The following example is to download the entire Web site to local.
Wget–mirror-p–convert-links-p./local URL
–miror: Open account Mirror Download
-P: Download all files that appear to be normal for HTML pages
–convert-links: After downloading, convert the cost to the link
-P./local: Save all files and directories to a locally specified directory
11, using wget–reject filter specified format download
You want to download a website, but you do not want to download pictures, you can use the following commands.
Wget–reject=gif URL
12. Use Wget-o to store download information in log file
You do not want the download information to be displayed directly at the terminal but rather in a log file, you can use the following command:
Wget-o Download.log URL
13, use wget-q limit total download file size
When you want to download more than 5M of files and exit the download, you can use the following command:
Wget-q5m-i filelist.txt
Note: This parameter does not work on a single file download and is only valid if it is recursive for downloading.
14, use Wget-r-A to download the specified format file
You can use this feature in the following situations
Download all pictures of a Web site
Download all videos of a website
Download all PDF files for a Web site
Wget-r-a.pdf URL
15, using wget FTP download
You can use wget to complete the FTP link download.
Using wget anonymous FTP download
wget Ftp-url
FTP download using wget user name and password authentication
Wget–ftp-user=username–ftp-password=password URL
Appendix:
Command format:
wget [parameter list] [target software, web site]
-v,–version Displays the software version number and exits;
-H,–HELP display software help information;
-e,–execute=command executes a ". Wgetrc" command