How to Change the Maximum Number of Retries in Wget?

When downloading files using the wget command-line utility, network instability or server issues can cause downloads to interrupt. By default, Wget will automatically attempt to resume a failed download up to 20 times before giving up. This article provides a quick overview of how to modify this limit using the --tries option for individual commands, how to configure a permanent change via the .wgetrc file, and how to set infinite retries for persistent downloads.

Changing Retries for a Single Command

If you only need to adjust the retry limit for a specific download, you can use the -t or --tries option directly in your terminal command. This is ideal for one-off downloads where you know the server is particularly unstable or, conversely, when you want it to fail quickly without wasting time.

To set the maximum number of retries to a specific number, use the following syntax:

wget -t 5 https://example.com/file.zip

In this example, Wget will only attempt to connect 5 times before terminating the request. You can also use the full option name:

wget --tries=5 https://example.com/file.zip

Setting Infinite Retries

In scenarios where you are downloading a critical, large file over a highly unreliable connection, you might want Wget to keep trying indefinitely until the download succeeds.

To configure infinite retries, set the value to 0 or inf:

wget -t 0 https://example.com/large-file.iso

Alternatively, this command achieves the exact same result:

wget --tries=inf https://example.com/large-file.iso

Making the Change Permanent

If you find yourself constantly changing the retry limit, you can alter Wget’s default behavior permanently by editing the configuration file. Wget reads settings from a file named .wgetrc located in your home directory.

  1. Open the file in a text editor, such as Nano: nano ~/.wgetrc
  2. Add or modify the tries line to your preferred number. For example, to set the global default to 10 retries, add: tries = 10
  3. Save and close the file.

If you want to apply this change globally for all users on a Linux system, you can edit the system-wide configuration file instead, which is typically located at /etc/wgetrc.