Home Linux Commands How to Download Files with Wget Command in Linux

How to Download Files with Wget Command in Linux

Wget command is a command-line tool that downloads files over the internet to your Linux system. It accepts multiple options which alter the nature of the file download such as saving a file with a different name, downloading a file to a specified location on the Linux system other than the present working directory, limiting the bandwidth and so much more.

[ You might also like: How to Download Files with Curl Command in Linux ]

In our guide, we explore different wget command usage examples in Linux.

Installing Wget in Linux

The wget command will usually ship, by default, with most modern Linux distributions. However, you might chance upon a Linux system that does not have the wget tool installed.

To confirm if the wget command is installed, run the command:

$ wget 

If not installed, you will get the following error.

-bash: wget: command not found
Wget Command Not Found
Wget Command Not Found

If that’s your situation, worry not. You can easily install the wget tool using your distribution’s package manager. Here’s how to install the wget command in various Linux distributions.

$ sudo apt install wget         [On Debian, Ubuntu and Mint]
$ sudo yum install wget         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a net-misc/wget  [On Gentoo Linux]
$ sudo pacman -S wget           [On Arch Linux]
$ sudo zypper install wget      [On OpenSUSE]    

The Wget Command Syntax

The wget command utility takes the syntax shown.

$ wget [options] [url]

The options refer to the flags or command-line arguments used along with the wget command to determine how the command will be executed.

The URL is the domain or the link to the resource or file to be downloaded.

Without much further ado, let us brush over some wget command usages and options.

1. Download a File with Wget Command in Linux

Without any command options, the Wget command simply downloads the file from the URL provided. In this example, we are downloading the latest Go binary file to our current working directory.

$ wget https://go.dev/dl/go1.18.linux-amd64.tar.gz
Wget Download File in Linux
Wget Download File in Linux

2. Rename a File While Downloading with Wget Command

The -O option allows you to save the file you are downloading using a different name. In this example, we are downloading the Go binary file and saving it as go.tar.gz.

$ wget -O go.tar.gz https://go.dev/dl/go1.18.linux-amd64.tar.gz
Wget Download File with Different Name
Wget Download File with a Different Name

3. Download File to Specific Directory with Wget Command

In previous examples, we have downloaded the files in the present working directory. Use the -P option (Uppercase P) to download the file to a different directory.

In this example, we are downloading the Go binary to the /tmp folder.

$ wget -P /tmp/ https://go.dev/dl/go1.18.linux-amd64.tar.gz

To confirm this, run the command:

$ ls /tmp | grep -i go
Wget Download File to Different Directory
Wget Download File to Different Directory

4. Download Multiple Files with Wget Command

Instead of downloading files each at a time, you can save the URLs of the resources to be downloaded in a text file which will act as an input file that will be read by the wget command.

Wget command reads the URLs from the input file and downloads or retrieves the resources from the internet.

In the example below, we have saved URLs in the download_files.txt text file. We will download WordPress, Go, and Node.JS binary files sequentially without intervention.

List of URL's to Download
List of URLs to Download

To download all the resources, use the -i option to specify the input file which contains the URLs of the resources to be downloaded.

$ wget -i download_files.txt
Wget Download Multiple Files
Wget Download Multiple Files

5. Resume Broken File Download with Wget Command

Sometimes a network downtime or service downtime can interrupt a file download. This usually leads to a broken file. Thankfully, the '-c' option can be used to resume a file download instead of starting all over again.

In the example below, we are resuming an interrupted download of the Download Rocky Linux ISO image using the -c option.

$ wget -c https://download.rockylinux.org/pub/rocky/8/isos/x86_64/Rocky-8.4-x86_64-minimal.iso

6. Download Files in Background with Wget Command

Downloading an enormous file can take quite a while, and this can be inconvenient especially when you have a lot to do. The workaround is to free up the terminal so that you have a workspace to continue with work.

The -b option downloads files in the background and frees up your terminal, in effect, allowing you to focus on running other pressing tasks.

$ wget -b https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.5.tar.xz
Wget Download File in Background
Wget Download File in Background

The output is generated in a log file called wget-log. To view the output of the download, view this log file as shown.

$ tail wget-log
View Wget Logs
View Wget Logs

The output shows that the file was successfully downloaded.

7. Limit File Download Speed with Wget Command

You can restrict or set a cap to the download speed using the --limit-rate option. This helps you to avoid bandwidth depletion especially when you have other concurrent tasks that are using up the same connection such as streaming or gaming.

The desired speed can be set in kilobytes (k), megabytes (m), or gigabytes (g). In the following example, the download speed for the Alpine Linux ISO has been set to 400 Kilobytes.

$ wget --limit-rate=100k https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-standard-3.15.3-x86_64.iso
Wget Limit File Download Speed
Wget Limit File Download Speed

8. Mirror a Website with Wget Command

The -m option allows you to mirror or download a site to your system for local browsing.

$ wget -m https://www.website.com/

Additional parameters can be provided for easier browsing of the downloaded site. Let’s take an additional example.

$ wget -m -k -p wget -m https://www.website.com/

Here. we have two additional options -m, -k and -p. The -k option converts the links in downloaded documents into a format that they can be viewed. The -p option downloads the CSS, JS, and any files required to view the HTML pages offline.

9. Increase the Number of File Retries with WGet Command

In the event of an interruption such as a degraded network or bandwidth, the wget command usually comes to the rescue and attempts to establish the connection.

It tries 20 times by default to complete the download successfully. The '--tries' flag enables you to specify the number of retry attempts. In this example, we’ve set the number of retries at 30.

$ wget --tries=30 https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-standard-3.15.3-x86_64.iso

10. Ignore SSL Certificate Error with Wget Command

Use the --no-check-certificate option to ignore the SSL certificate check in the case where an incorrect certificate prevents the download from proceeding.

$ wget --no-check-certificate https://website-with-invalid-ssl.com

We have outlined the most common ways in which the wget command is used to download files on a Linux system. Please check out the official documentation on additional wget command options.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.