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.
Table of Contents
- Installing Wget
- Wget Command Syntax
- 1. Download a File Using Wget
- 2. Using Wget Command to Rename Downloaded File
- 3. Download Multiple Files Using Wget
- 4. Resume a Download Using Wget
- 5. Download Files in Background Using Wget
- 6. Limit the Download Speed Using Wget
- 7. Download a File to a Specific Directory
- 8. Download Password Protected Files via HTTP or FTP Using Wget
- 9. Skipping Certificate Check
- 10. Download a Website Content Using 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
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:
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
-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
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.
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
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
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
-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 -b http://mirrors.mit.edu/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
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
7. Download a File to a Specific Directory
wget downloads files under the current working directory. But, of course,
wget can save the downloaded files in a predefined directory.
-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
The above command will download the ISO file under the
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 --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://188.8.131.52/archlinux/iso/2022.04.05/archlinux-2022.04.05-x86_64.iso
10. Download a Website Content Using Wget
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
|-m||Makes your download recursive.|
|-k||All links will be converted for proper offline usage.|
|-p||This will include all necessary files such as images, CSS, JS, etc.|
|-P||Ensures that all content goes to our specified |
When the process is complete, you will be able to open the downloaded website locally and locate all of the files in the
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.