The Wget command is a command line utility in Linux that allows users to download files from the internet. It can be used to download files from a range of sources, including HTTP, HTTPS, and FTP servers. The Wget command is commonly used to download files from websites, but it can also be used to download files from other servers and sources.
The Wget command’s primary function is to retrieve files from the internet and save them to a local directory. It is often used to download files that are required for system updates or to download large files such as software packages or multimedia files. The Wget command is particularly useful for downloading files from servers that require authentication, as it can be used to download files using HTTP and FTP username and password credentials.
In this tutorial, we will show you how to use the Wget command through practical examples and detailed explanations of the most common Wget options.
Table of Contents
Install Wget on Linux
Currently, the wget package is pre-installed on most Linux distributions.
To check if the Wget package is installed on your system, open your console, type
wgetand hit Enter. If you have wget installed, the system will print
wget: missing URL; otherwise it will print the
wget command not found.
If wget is not installed, you can easily install it using your distribution’s package manager.
Installing wget on Ubuntu and Debian
sudo apt update
sudo apt install wget
Installing wget on CentOS and Fedora
sudo yum install wget
Basic syntax of the Wget command
Before we get into how to use the
wget, let’s start by looking at the basic syntax.
In this syntax,
[option] represents one or more options or flags that can be used to customize the behavior of the Wget command, and
[URL] represents the URL of the file or resource that you want to download.
wget [options] [url]
To use the Wget command, you will need to specify at least one URL as an argument. You can specify multiple URLs by separating them with spaces. For example, to download multiple files, you can use a command like this:
wget https://example.com/path/to/file1.zip https://example.com/path/to/file2.zip
The Wget command supports a wide range of options and flags that can be used to customize its behavior. Some of the most common options and flags that are used with the Wget command include:
-O: specifies the output file name
-P: specifies the directory in which to save the downloaded file
-r: downloads files recursively
--accept: downloads only files with a specific file extension
--user: specifies the username for HTTP or FTP authentication
--password: specifies the password for HTTP or FTP authentication
--limit-rate: limits the download speed to a specified rate
These are just a few of the many options and flags that are available with the Wget command. You can use the
wget --help command to view a complete list of available options and learn more about how to use them.
Examples of Using the Wget Command in Linux
Here are some examples of using the Wget command in Linux:
- Downloading a file from a URL:
- Downloading a file and saving it with a specific name:
wget https://example.com/path/to/file.zip -O myfile.zip
- Downloading all files in a directory:
wget -r https://example.com/path/to/directory
- Downloading files with a specific file extension:
wget --accept=pdf https://example.com/path/to/directory
- Downloading files using HTTP authentication:
wget --user=username --password=password https://example.com/path/to/file.zip
These are just a few examples of using the Wget command in Linux. You can use a wide range of options and flags to customize the behavior of the Wget command and download files from a variety of sources.
With Wget, you can download multiple files, resume partial downloads, mirror websites, and combine Wget options according to your needs.
For more information on Wget, visit the GNU wget man page.