Top 10 Use Cases of Wget Command (with Examples)

This guide will show you how to use the wget command through 10 commonly used examples.

Wget is a command-line utility for downloading files from the web, created by the GNU Project. The name is a combination of “World Wide Web” and “get.”

Wget allows you to download files using HTTP, HTTPS, and FTP protocols. In addition, it gives you the ability to download multiple files, resume downloads, limit bandwidth, perform recursive downloads, download in the background, mirror a website, and even more.

By the end of this guide, you’ll know everything there is to know about the wget command and how to use it to download files from the Internet.

Installing Wget

The wget package comes pre-installed on most Linux distros. However, if the wget command is not installed on your system, you can easily install it using the package manager.

Installing Wget on Ubuntu, Debian, and Other Debian-based Distros

sudo apt install wget

Installing Wget on Fedora, RHEL, and Other RHEL-based Distros

sudo dnf install wget

Installing Wget on Manjaro, Arch Linux, and Other Arch Linux-based Distros

sudo pacman -S wget

You’ll be able to use the wget command once the setup is complete. But, first, I’ll show you the ten most used wget command examples that you can use in your everyday work to get you started.

Wget Command Syntax

The wget command expressions take the following syntax:

wget [OPTIONS] [URL]
  • [OPTIONS] tells what to do with the [URL] argument provided after.
  • [URL] is the file or the directory you want to download.

1. Download a File Using Wget

The simplest way to use wget is to provide it with the location of a file to download. Then, when no options are specified, wget downloads the resource specified in the [URL] to the current directory.

For example, you can get the Arch Linux installation ISO image file by doing the following:

wget http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
How to download a file with wget

As a result, a file named archlinux-2022.04.05-x86_64.iso downloads in the current working directory. In addition, you’ll also see information such as the download progress, speed, size, time, and date.

2. Using Wget Command to Rename Downloaded File

Pass the -O option followed by the preferred name to save the downloaded file under a different name.

For example, the command below will save the Arch Linux installation ISO image file as arch-install.iso instead of its original name.

wget -O arch-install.iso http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
Using the wget command to rename downloaded file

3. Download Multiple Files Using Wget

If you want to use wget to download multiple files at once, use the -i option followed by the path to the file containing a list of the URLs to be downloaded. In addition, each URL must be placed on its line.

In this example, we will retrieve the ISO installation images of Arch Linux and Debian by using wget. First, however, we’ll need to create a text document and insert the download URLs into it to do so.

So, first, let’s create a file with a name of our choice, for example, urls.txt, and put in it the necessary URL addresses to the files we want to download.

vim urls.txt
How to download multiple files using wget

Next, you need to use the -i option followed by the file name to download all the files stored in our text file.

wget -i urls.txt
How to download multiple files using wget

That’s all. Just wait for the process to finish.

4. Resume a Download Using Wget

If you lose your internet connection, your download may be interrupted. Indeed, this is a fairly common occurrence when downloading large files.

So, instead of restarting the download from scratch, use the -c option to continue it:

wget -c http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
How to resume download using wget

However, if the remote server does not support resumed downloads, wget will restart the download and overwrite the existing file.

5. Download Files in Background Using Wget

Adding the -b option to wget will send the download in the background immediately after the download start. If no output file is specified via the -o option, the output is redirected to the wget-log file.

wget -b http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
How to download files in background with wget

In addition, you can view the actions performed in the background by wget by simply viewing the contents of the wget-log file. For example, the first ten lines of its contents are shown in the image above.

6. Limit the Download Speed Using Wget

When downloading a large file over a slow internet connection, it is sometimes necessary to limit the download rate of the wget command to prevent it from using all of your bandwidth.

The following example will download the Arch Linux installation ISO image and limit the download speed to 1MB:

wget --limit-rate=1m http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
How to limit the download speed when using wget

7. Download a File to a Specific Directory

By default, wget downloads files under the current working directory. But, of course, wget can save the downloaded files in a predefined directory.

The -P option is used to set the directory prefix to which all retrieved files will be saved.

wget -P /tmp/ http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
Download a file to a specific directory using wget

The above command will download the ISO file under the /tmp directory.

8. Download Password Protected Files via HTTP or FTP Using Wget

If the website you want to download is password-protected, the standard wget commands will fail, displaying an access denied error while attempting to download.

However, we could use the option below to include the username and password for the password-protected website alongside the wget commands used to retrieve the file.

For example, to download a file from a password-protected HTTP server, you’ll need to specify the username and password as in this wget example:

wget --http-user=username --http-password=password https://www.example.com/filename.tar.gz

Alternatively, to download a file from a password-protected FTP server, the wget command is:

wget --ftp-user=username --ftp-password=password ftp://ftp.example.com/filename.tar.gz

9. Skipping Certificate Check

If you want to use wget to download a file from a server with an invalid SSL certificate, for example, expired or not from a trusted issuer, you can use the --no-check-certificate option to force wget to ignore such errors.

wget --no-check-certificate https://18.7.29.125/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
How to skip the ceriticate check when using wget

10. Download a Website Content Using Wget

The wget command can also be used to download the entire content of a website. So you can use use the -m option to create a website mirror.

This will make a complete local copy of the website by following and downloading all internal links and website resources.

wget -m -k -p -P /tmp/web/ https://www.example.com
-mMakes your download recursive.
-kAll links will be converted for proper offline usage.
-pThis will include all necessary files such as images, CSS, JS, etc.
-PEnsures that all content goes to our specified /tmp/web/ directory.

When the process is complete, you will be able to open the downloaded website locally and locate all of the files in the /tmp/web/ directory.

Conclusion

By completing this guide, you have learned mot common uses for the wget command. You can now use it to download multiple files at once, resume partial downloads, mirror websites, and combine the wget options to meet your specific needs.

In addition to this article, if you prefer to use the GUI client to download larger files that usually also have a torrent download option, we recommend our guide: “Best Torrent Clients You Can Use on Linux Desktop.”

For more detailed information about the wget command, you can head to the command’s man page.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%

Leave a Reply

Your email address will not be published. Required fields are marked *