Wget in Terminal – Download Files and Websites

Wget is a simple command-line tool used to download files and web pages from the internet. It works directly from the terminal and supports HTTP, HTTPS, and FTP downloads. You can use it to easily download files, resume interrupted downloads, save content with custom names, and perform other useful tasks.

Features of Wget:

  • Download files from a URL.
  • Resume interrupted downloads.
  • Download multiple URLs from a file.
  • Limit download speed.
  • Set download timeouts.
  • Download entire websites.
  • Check whether a file is available without downloading it.
  • Use HTTP headers and custom User-Agent.
  • Download files over HTTPS and FTP.

Wget Installation Commands

Below are the commands to install Wget according to your terminal system.

For Termux, Update Termux packages.

pkg update && pkg upgrade -y

Install Wget.

pkg install wget -y

On Debian/Ubuntu-based Linux systems, install Wget with:

sudo apt install wget

Wget is now installed and ready to use.

Wget Usage Commands

After installing Wget, you can use different commands to download files, control downloads, and work with websites from the terminal.

Download a file.

wget https://example.com/file.zip

Download a file and save it with a custom name.

wget -O myfile.zip https://example.com/file.zip

Download a file and save it to a specific directory.

wget -P ~/Downloads https://example.com/file.zip

Resume a partially downloaded file.

wget -c https://example.com/file.zip

Download multiple URLs from a file.

Create a file containing the URLs:

nano urls.txt

Then run:

wget -i urls.txt

Limit the download speed.

wget --limit-rate=500k https://example.com/file.zip

Set the number of download retries.

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

Set a connection timeout.

wget -T 30 https://example.com/file.zip

Run Wget quietly without showing normal output.

wget -q https://example.com/file.zip

Show detailed download information.

wget -v https://example.com/file.zip

Save Wget output to a log file.

wget -o download.log https://example.com/file.zip

Append output to an existing log file.

wget -a download.log https://example.com/file.zip

Check the server response without downloading the file.

wget -S --spider https://example.com/file.zip

The --spider option checks the URL without saving the file.

Check the installed Wget version.

wget --version

Display the help menu.

wget --help

Download Websites with Wget

Wget can also download web pages and their required files.

Download a webpage.

wget https://example.com

Download a website recursively.

wget -r https://example.com

Download a webpage with its required images and other page files.

wget -p https://example.com

Download a website and convert links for offline use.

wget -r -k https://example.com

Mirror a website.

wget -m https://example.com

Set the maximum recursion depth.

wget -r -l 2 https://example.com

Avoid going to the parent directory.

wget -r -np https://example.com/downloads/

Save downloaded files into a specific directory.

wget -P ~/website https://example.com/file.zip

Download only specific file types.

wget -r -A pdf https://example.com

Reject specific file types.

wget -r -R jpg,png https://example.com

HTTP Options

Wget also provides options for sending custom HTTP information when downloading resources.

Set a custom User-Agent.

wget -U "Mozilla/5.0" https://example.com

Send a custom HTTP header.

wget --header="Accept-Language: en-US" https://example.com

Send POST data.

wget --post-data="name=John&age=25" https://example.com/form

Save HTTP response headers with the downloaded file.

wget --save-headers https://example.com

Disable cookies.

wget --no-cookies https://example.com

Load cookies from a file.

wget --load-cookies cookies.txt https://example.com

Save cookies to a file.

wget --save-cookies cookies.txt https://example.com

HTTPS Options

Wget supports HTTPS downloads and provides options for controlling certificate verification.

Download only through HTTPS links.

wget --https-only https://example.com/file.zip

For testing with a server that has an invalid or self-signed certificate, you can disable certificate checking:

wget --no-check-certificate https://example.com/file.zip

Use --no-check-certificate only when you understand the security risk, because it disables normal certificate verification.

FTP Downloads

Wget can also download files from FTP servers.

Download an FTP file.

wget ftp://example.com/file.zip

Use an FTP username.

wget --ftp-user=username ftp://example.com/file.zip

Ask for the FTP password.

wget --ask-password ftp://example.com/file.zip

Useful Wget Commands

Download a file without creating extra directories.

wget -nd https://example.com/files/file.zip

Do not overwrite an existing file.

wget -nc https://example.com/file.zip

Wait between multiple downloads.

wget -w 5 -i urls.txt

Use IPv4 only.

wget -4 https://example.com/file.zip

Use IPv6 only.

wget -6 https://example.com/file.zip

Set a download quota.

wget -Q 50M -i urls.txt

Run Wget in the background.

wget -b https://example.com/file.zip

Use a proxy.

wget -e use_proxy=yes -e http_proxy=http://127.0.0.1:8080 https://example.com

Show the current help information.

wget -h

Wget has many more options, but these commands cover the most useful features for beginners. You can combine options when you need more control over a download.

Wget Overview

Wget is a useful terminal tool for downloading files and web pages. It supports many options for managing downloads, saving files, resuming interrupted downloads, and working with multiple URLs. You can start with simple download commands and explore other options when needed.

SHARE THIS POST: