15 Linux Wget download examples Ultimate Guide

Linux wget to download files is a tool that is used in the command line. For Linux users is an essential tool, especially for network administrators often have to download some software or restore the backup to the local server from a remote server. If we use the virtual host to handle such matters we can only start with the remote server to download to our computer disk, then use the ftp tool to upload to the server. This will not only waste of time and energy, it is not no way to do. And to the Linux VPS, you can download it directly to the server without going through the uploading this step. wget tools small but functional, it supports breakpoint download function, supports FTP and HTTP download, support proxy servers and set up convenient and simple. Below we explain in the form of examples of how to use wget.

1, using wget to download a single file

The following example is downloading a file from the network and stored in the current directory

wget http://www.xxxxxx.com/xxxxx-1.1-zh_CN.zip

  

Progress bar is displayed in the download process, comprising (percentage of download completed, the bytes have been downloaded, the current download speed, remaining download time).

2, using wget -O download and save the file with a different name

wget will default to the last line with "/" behind the characters to command, usually for the download file name dynamically linked incorrectly. Error:? The following example will download a file name and save download.php id = 1080

wget http://www.xxxxxx.com/download?id=1

  Even if the downloaded file is zip format, it still 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, download speed using wget --limit -rate

When you execute wget, which by default will take all possible broadband download. But when you're ready to download a large file, but you also need to download other files it is necessary to speed up.

wget --limit-rate=300k http://cn.wordpress.org/wordpress-3.1-zh_CN.zip

  

4, using wget -c HTTP

Use wget -c to restart interrupted file download:

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

  

For downloading large files when we suddenly interrupted due to network and other very helpful, then we can continue to download instead of re-downloading a file. You can use -c parameters need to continue interrupted downloads.

5, background downloading using wget -b

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

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

tail -f wget-log

  

6, camouflage agent name download

Some sites can refuse your request to download at the discretion of the proxy name instead of the browser. But you can --user-agent parameter camouflage.

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" 下载链接

  

7, using wget --spider test download link

When you plan time to download, you should test the download link is valid for a predetermined time. We can increase --spider parameters to be checked.

wget --spider URL

  If the correct download link will be displayed

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 could contain further links, but recursion is disabled -- not retrieving.

  This ensures that the download can be performed 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 following circumstances spider parameters:

Check before a timing download 7.1

7.2 interval to detect whether the site is available

7.3 dead link check the website page

8, using the number of retries increases wget --tries

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

wget --tries=40 URL

  

9, download multiple files using wget -i

First, keep a file download link

cat>filelist.txt url1 url2 url3 url4

Then use this file to download and parameter -i

wget -i filelist.txt

10, using wget --mirror mirror sites

The following example is to download the entire site to a local.

wget --mirror -p --convert-links -P ./LOCAL URL

--miror: Account Mirror Download

-p: download all html page to display the normal file

--convert-links: After the download, conversion costs link

-P ./LOCAL: Save all files and directories to a local specified directory

11, using wget --reject filter specified format download

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

wget --reject=gif url

12, using wget -o to download information into the log file

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

wget -o download.log URL

13, using wget -Q limit the total download file size

When the file you want to download more than 5M exit download, you can use the following command:

wget -Q5m -i filelist.txt

Note: This parameter does not work on a single file to download, if only recursive downloads effective.

14, using wget -r -A download the specified format file

You can use this function in the following cases

All the pictures to download a website

All video to download a website

All PDF files downloaded a Web site

wget -r -A.pdf url

15, using wget FTP download

You can use wget to download the complete ftp links. Anonymous ftp download using wget

wget ftp-url

Use wget user name and password authentication ftp download

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

Source: http://www.zhumaohai.com/  reproduced please retain copyright






Reproduced in: https: //my.oschina.net/tiwer/blog/199861

Guess you like

Origin blog.csdn.net/weixin_34056162/article/details/91708522