Perhaps simple commands
wget URL can not meet our daily use. We need to add more commands with wget options.
When you forget some options, you can use
--help ) to recall what you want.
By default, Wget outputs full information to the terminal when you download a file. You can use the
--quiet ) option to turn off all output.
Download the favicon of
vpsname.com without showing any output.
wget -q https://vpsname.com/favicon.ico
Before saving a file, Wget checks whether the file exists in the desired directory. If it does, Wget adds a number to the end of the file. If you run the command above one more time, Wget would create a file named
favicon.ico.1. This number increases every time you download a file to a directory that already has a file with the same name.
--output-document=file name)is not intended to mean simply "use the name file instead of the one in the URL"; rather, it is analogous to shell redirection:
wget -O file URL is intended to work like
wget -O - URL > file. The file will be truncated immediately, and all downloaded content will be written there. However, you can simply understand it as renaming the downloaded file.
wget -O vpsname.ico https://vpsname.com/favicon.ico # same way wget --output-document=vpsname.ico https://vpsname.com/favicon.ico
Well, when you execute this same command again, Wget will not add a number to the end of the file. Yes, the original file has been overwritten. You can run the command above as many times as you like and Wget will download the file and overwrite the existing one. If you run the command above without the
-O option, Wget will create a new file each time you run it.
o. You should use the capital "O" here.
Wget will store files in the current directory by default. You can use the
-P option to specify the directory where you want to save the file.
Now my current directory is
/root, download the .ico file you downloaded previously, but this time save it with
-P option to the
wget -P wget/ https://vpsname.com/favicon.ico
You can use
ls wget to see if the file was saved in the
If you want to download multiple files use Wget, you can create a target file with URLs of the files you wish. Then use the Wget
-i option followed by the target file to download.
First, create a target file name
target.txt and insert the URLs that you want to download.
echo "https://vpsname.com/usr/uploads/2019/04/2267822245.png" >> target.txt echo "https://vpsname.com/usr/uploads/2019/12/966351515.jpg" >> target.txt echo "https://vpsname.com/usr/uploads/2020/11/2166750455.png" >> target.txt
Now you can use Wget with
-i option to download these three images to
wget -i target.txt -P /root/wget/
When you want to limit the download speed to preserve resources for other tasks. You can limit the download speed by using the
--limit-rate option followed by the maximum speed allowed in kiloBits per second and the letter k.
Download the favicon of
vpsname.com with a speed of
wget --limit-rate 1k https://vpsname.com/favicon.ico
This is useful when you don't want Wget to consume the entire available bandwidth.
This command is useful when your download is interrupted. You can resume it by using the
This time you can try to download
Debian 11 ISO file, and then press
Ctrl + C to cancel the download before the command finishes.
To resume the download, add the
-c option. Note that this will only work if you run this command in the same directory as the incomplete file.
wget -c https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-cd/debian-11.4.0-amd64-netinst.iso
It is worth mentioning that not all links support resuming downloads.
Set the network timeout to seconds. This is equivalent to specifying
When interacting with the network, Wget can check for timeout and abort the operation if it takes too long. This prevents anomalies like hanging reads and infinite connects. The only timeout enabled by default is a 900-second read timeout. Setting a timeout to 0 disables it altogether. Unless you know what you are doing, it is best not to change the default timeout settings.
You can set a timeout by using the
--timeout) option followed by the time in seconds.
Useing this command you can set the timeout to 5 seconds.
wget -T 5 https://vpsname.com/favicon.ico
You can also set how many times Wget attempts to download a file after being interrupted by passing the
--tries) option followed by the number of tries.
Using this command, you can limit the number of tries to 3.
wget -t 3 https://vpsname.com/favicon.ico
The default is to retry 20 times, with the exception of fatal errors like "connection refused" or "not found" (404), which are not retried.
Since Wget uses
GNU getopt to process command-line arguments, every option has a long form along with the short one. Long options are more convenient to remember, but take time to type. You may freely mix different option styles, or specify options after the command-line arguments.