Loading...

Lab 70: Downloading Files with wget

Download files from a URL using wget, control the output filename, and recover safely from interrupted transfers. Run long downloads in the background while preserving logs for verification.

network download core

Scenario

You need to download a software package from the internet. Your task is to fetch a tarball from a URL, save it with a custom name, resume a partial download, and run a download in the background while capturing output for later review.

Operator context

wget is common in build pipelines and on minimal servers where a browser is not available. Being able to resume transfers and background long downloads keeps maintenance work reliable over unstable connections.

Objective

  • Download a file from a URL using wget.
  • Save a download with a custom output filename using -O.
  • Resume a partial download using -c.
  • Start a background download using -b and validate where output is written.

Concepts

  • URL to filename mapping: by default, the last path segment becomes the output filename.
  • Deterministic naming: -O forces a predictable output path for scripts and pipelines.
  • Resume semantics: -c continues from the current local size when the server supports partial content.
  • Background jobs: -b detaches and writes output to a log file you can review later.
  • Verification: confirm file size, checksum, or signature when integrity matters.

Walkthrough

Step 1 : Download the file from the URL.
Command
wget https://example.com/sample.tar.gz

This downloads the remote file into the current directory using the filename from the URL path.

--2025-01-01 10:00:00--  https://example.com/sample.tar.gz
Resolving example.com (example.com)... 93.184.216.34
Connecting to example.com... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10240 (10K) [application/x-gzip]
Saving to: ‘sample.tar.gz’
sample.tar.gz        100%[===================>]  10.00K  --.-KB/s   in 0.02s
Step 2 : Download and save with a custom filename.
Command
wget -O custom.tar.gz https://example.com/sample.tar.gz

Use -O when you need a predictable output name, such as scripting downloads for automation.

Saving to: ‘custom.tar.gz’
custom.tar.gz      100%[===================>]  10.00K  --.-KB/s   in 0.02s
Step 3 : Resume a partially downloaded file.
Command
wget -c https://example.com/sample.tar.gz

If the local file exists and is incomplete, -c requests remaining bytes instead of restarting from the beginning.

Resuming download of ‘sample.tar.gz’.
HTTP request sent, awaiting response... 206 Partial Content
Length: 10240 (remaining: 2048)
sample.tar.gz        100%[+++++++++++++++++++]  2.00K  --.-KB/s   in 0.01s
Step 4 : Download in the background.
Command
wget -b https://example.com/sample.tar.gz

Background mode is useful when you want to continue working while the download runs. Output is written to wget-log by default.

Continuing in background, pid 12345.
Output will be written to ‘wget-log’.

Common breakpoints

Resume fails or restarts from the beginning

The server may not support partial downloads, or the remote file changed. Remove the partial file and re-download, or use a different mirror if available.

TLS / certificate validation errors

Verify the URL and system time, and confirm the host is trusted. Certificate errors are often a sign of the wrong endpoint or a man-in-the-middle risk.

Background download "disappears"

Check the log file and confirm the PID is still running. If the job exited, the log usually captures the reason.

Download succeeds but file is corrupted

Validate integrity with checksums or signatures when provided. If no checksum exists, re-download and compare sizes and hashes across attempts.

Cleanup checklist

If this was a practice run, remove the downloaded artifacts and log so your working directory stays clean.

Commands
ls -la
rm -f sample.tar.gz custom.tar.gz wget-log
Success signal

You can download with default naming, force an output name with -O, resume a partial transfer with -c, and confirm background activity via wget-log.

Reference

  • wget: Download content from a URL to a file.
    • wget <URL>: Download to the current directory using the URL filename.
    • -O <file>: Write output to a specific filename.
    • -c: Continue an interrupted download if supported by the server.
    • -b: Run in the background and write output to wget-log.