Download Files Reliably with Wget on Linux

A download drops halfway through a flaky connection, and wget can resume it instead of wasting the bandwidth you already spent. It can also check a URL without saving anything and retry ordinary failures on its own. This guide covers a small workflow for downloading a file, checking that a URL exists without saving it, and resuming a transfer after a network interruption. The examples use GNU Wget 1.21.4 from the installed wget package.

Allow about ten minutes for a first run. You need a shell, a writable destination directory, and the URL of a file you are allowed to retrieve. These examples do not need elevated privileges. Use sudo only when the destination is deliberately restricted, and check the path carefully before doing so.

1. Check the installed Wget

Confirm which executable will run and record its version:

$ command -v wget
/usr/bin/wget
$ wget --version | head -3
GNU Wget 1.21.4 built on linux-gnu.

The build on this machine has HTTPS and IPv6 support. Your output may differ on another distribution. The command syntax below is written for this installed version, whose manual page is dated 20 August 2026.

Checkpoint: if command -v wget prints nothing, stop and install the package through your normal system-management process. Do not copy a random binary into /usr/bin.

2. Download one file to the current directory

Run Wget with one URL. It normally derives the local filename from the URL and writes it in the current directory:

$ wget https://example.com/archive.tar.gz
--2026-09-27 19:36:24--  https://example.com/archive.tar.gz
Saving to: 'archive.tar.gz'
archive.tar.gz             100%[========================>]  ...  --.-KB/s    in 0s

2026-09-27 19:36:24 (.. MB/s) - 'archive.tar.gz' saved [..]

The exact size, speed and timestamp will change. The useful result is the final saved line and an exit status of zero:

$ printf '%s\n' "$?"
0
$ file archive.tar.gz
archive.tar.gz: gzip compressed data, ...

Wget retries ordinary transient failures by default, up to 20 attempts. Fatal errors such as a refused connection or HTTP 404 are not retried by that default. For a bounded job, make the retry policy visible:

$ wget --tries=5 --timeout=30 https://example.com/archive.tar.gz

--timeout=30 sets the DNS, connection and read timeouts together. It does not limit the total download time. A read timeout measures idle time, so a slow but continuously producing server can still take longer.

3. Avoid overwriting the wrong file

Wget's default behaviour depends on the other options in use. For a repeated single-file download without timestamping, recursion or --no-clobber, an existing file is preserved and the new copy normally receives a numeric suffix such as .1. That is safer than assuming the name is always replaced, but it can leave several copies in a directory.

Use a separate destination directory when the output is valuable:

$ mkdir -p "$HOME/Downloads/vendor-release"
$ cd "$HOME/Downloads/vendor-release"
$ wget https://example.com/archive.tar.gz
$ ls -lh archive.tar.gz

To refuse a download when the derived destination already exists, use --no-clobber:

$ wget --no-clobber https://example.com/archive.tar.gz
File 'archive.tar.gz' already there; not retrieving.

This protects an existing file from a fresh retrieval, but it is not a checksum check. A file with the right name can still be incomplete or unrelated. Compare a publisher's checksum when one is available.

Destructive action: --output-document=FILE, or -O FILE, truncates FILE immediately and writes all downloaded content there. It is useful for a deliberate single-file output, but it is not just a rename of the URL's filename:

$ wget --output-document=archive.tar.gz.new https://example.com/archive.tar.gz
$ test -s archive.tar.gz.new && echo "new file is non-empty"
new file is non-empty

Keep the original until you have checked the new file. If you accidentally chose the wrong output path, stop and inspect it before removing anything. No Wget undo command can restore a file that shell redirection or -O has truncated.

4. Resume a partial download

If a previous Wget process left a partial file, use --continue:

$ wget --continue https://example.com/archive.tar.gz
Length: ...
Saving to: 'archive.tar.gz'
archive.tar.gz             100%[========================>]  ...  --.-KB/s    in 0s
$ printf '%s\n' "$?"
0

Wget asks the server to continue at the local file's length. The server must support HTTP range requests or FTP continuation. Without --continue, a previous partial file is generally left alone and a new suffixed filename is used.

Safety boundary: --continue assumes the local file is the beginning of the current remote file. If the publisher replaced the remote content, Wget cannot prove that the bytes match, and the result can be corrupted. Delete or rename the partial file and start again when the source may have changed:

$ mv archive.tar.gz archive.tar.gz.partial-old
$ wget https://example.com/archive.tar.gz

Only remove archive.tar.gz.partial-old after checking that the new download is valid. This recovery step is reversible while the renamed file remains in place.

5. Test a URL without downloading it

Use spider mode when you need to check reachability or inspect the response without writing the page:

$ wget --spider --server-response --timeout=10 https://example.com/
Spider mode enabled. Check if remote file exists.
HTTP/1.1 200 OK
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.

The status line is the useful evidence. A 404 or an authentication response is different from a DNS or connection failure, so retain the command's exit status for scripts rather than parsing the prose:

if wget --spider --quiet --timeout=10 "$url"; then
    printf '%s\n' 'URL is reachable'
else
    status=$?
    printf 'URL check failed with status %s\n' "$status" >&2
    exit "$status"
fi

--server-response prints response headers. Do not combine it with a quiet diagnostic policy unless you deliberately want only the exit status.

6. Download a controlled list

For several independent URLs, put one URL per line in a file you have reviewed, then pass it with --input-file:

$ cat urls.txt
https://example.com/one.tar.gz
https://example.com/two.tar.gz
$ wget --input-file=urls.txt --wait=2 --tries=3

--wait=2 inserts a two-second pause between retrievals. It reduces request frequency and makes a batch less abrupt for the server. A quota does not protect a single oversized file: Wget checks it at the end of each file, so one file can exceed the quota before the batch stops.

Review urls.txt before running it. A URL list can cause many downloads, follow redirects to unexpected hosts, or consume substantial disk space. Use a dedicated directory and check free space first.

Done means