This is the third day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021.
The wget command is used to download files from the Web in Linux. It supports HTTP, HTTPS, and FTP protocols. Wget also provides many options, such as downloading multiple files, background download, and proxy, which are very convenient to use.
Here’s how to use wGET.
Use of the wget command
Syntax format
wget [options] [url]
Copy the code
For example, use wget to download the redis tar.gz file:
Wget HTTP: / / https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
This command downloads files to the current working directory. During the download process, the progress bar, file size, and download speed are displayed.
Here are a few common option parameters.
Use the -o option to save the downloaded file under a different name
To save the downloaded file by another name, use the -o option followed by the specified name:
Wget -o redis. Tar. Gz https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Use the -p option to download the file to the specified directory
By default, wget saves the downloaded files in the current working directory. Using the -p option to save the files to a specified directory, for example, the following will download the files to the /usr/software directory:
Wget - P/usr/software at https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Use the -c option for breakpoint continuation
When we download a large file, if the network is disconnected and the download does not complete, we can use the -c option of the command to resume the download and let the download continue from the breakpoint without having to download from the beginning.
Wget -c https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Use the -b option to download in the background
We can use the -b option to download files in the background:
Wget - b at https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
By default, download process logs are redirected to the wget-log file in the current directory. To view the download status, use tail -f wget-log.
Use the -i option to download multiple files
If you want to download more than one file at a time, you need to create a text file and add all the urls to it, each of which must be a single line.
vim download_list.txt
Copy the code
Then use the -i option, followed by the text file:
wget -i download_list.txt
Copy the code
Use the –limit-rate option to limit the download speed
By default, the wget command will download at full speed, but sometimes downloading a very large resource can consume too much available bandwidth and affect other tasks using the network. In this case, you may want to limit the download speed by using the –limit-rate option. For example, the following command limits the download speed to 1m/s:
Wget - limit - rate = 1 m https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Use the -u option to set the agent download
If the remote server prevents WGET from downloading the resource, we can use the -u option to simulate the browser download, such as the following simulated Google Browser download.
Wget -u 'Mozilla/5.0 (Windows NT 10.0; Win64; X64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome / 81.0.4044.43 Safari / 537.36 'https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Use the –tries option to increase the number of retries
If there is a network problem or the download of a large file may fail, wget defaults to 20 retries. You can use the -tries option to increase the number of retries.
Wget - tries = https://download.redis.io/releases/redis-6.0.8.tar.gzCopy the code
Download through FTP
If you want to download files from the password-protected FTP server, specify the username and password in the following format:
wget --ftp-user=<username> --ftp-password=<password> url
Copy the code
In addition, there are many options available for Wget, which are not listed here, but wget is a very useful tool.
Original is not easy, if small partners feel helpful, please click a “like” and then go ~
Finally, thank my girlfriend for her tolerance, understanding and support in work and life!