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 commonly used 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.

What You’ll Practice

  • Fetching remote content with wget <URL>.
  • Controlling output filenames with wget -O.
  • Continuing interrupted downloads with wget -c.
  • Running downloads in the background with wget -b and reviewing wget-log.

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’.

Reference

  • wget <URL> : Downloads a file from the provided URL to the current directory.
  • -O <file> : Writes output to a specific filename instead of the name in the URL.
  • -c : Continue an interrupted download by requesting remaining bytes.
  • -b : Run in the background and write output to wget-log.