Use Wget Downloading with Wget Options

Last Updated: Sun, July 24, 2022

Wget Options

Perhaps simple commands wget URL can not meet our daily use. We need to add more commands with wget options.

Print a help message

When you forget some options, you can use -h (or --help ) to recall what you want.

wget -h

Turning Wget’s output off

By default, Wget outputs full information to the terminal when you download a file. You can use the -q (or --quiet ) option to turn off all output.

Download the favicon of without showing any output.

wget -q

Without showing any output

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.

Download the file to the specified name / Overwriting a downloaded file

Use of -O (or --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
# same way
wget --output-document=vpsname.ico

Download the file to the specified name

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.

  • Attention should be paid to distinguishing the case of the letter O or o. You should use the capital "O" here.

Downloading a file to a specific directory

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 /root/wget.

wget -P wget/

Downloading a file to a specific directory

You can use ls wget to see if the file was saved in the wget directory.

Downloading multiple files

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 "" >> target.txt
echo "" >> target.txt
echo "" >> target.txt

Now you can use Wget with -i option to download these three images to /root/wget directory.

wget -i target.txt -P /root/wget/

Use Wget Downloading Multiple Files

Limiting download speed

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 with a speed of 15 kB/S.

wget --limit-rate 1k

Limiting download speed

This is useful when you don't want Wget to consume the entire available bandwidth.

Resuming a download

This command is useful when your download is interrupted. You can resume it by using the -c (or --continue) option.

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

esuming a Download

It is worth mentioning that not all links support resuming downloads.

Setting a timeout

Set the network timeout to seconds. This is equivalent to specifying --dns-timeout, -connect-timeout, and --read-timeout simultaneously.
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 -T (or --timeout) option followed by the time in seconds.

Useing this command you can set the timeout to 5 seconds.

wget -T 5

Maximum Number of Tries

You can also set how many times Wget attempts to download a file after being interrupted by passing the -t (or --tries) option followed by the number of tries.

Using this command, you can limit the number of tries to 3.

wget -t 3

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.

If you interest in my articles, please consider buying me a coffee.

Write Your Comment