The Wget is a command-line utility that is used to download files and webpages from the web. Various internet protocols like HTTP, HTTPS, and FTP can be used to access and retrieve the files. We can specify the different options with the Wget command in order to perform different options.

This article explains the use of the Wget command to download the file from the command-line. Moreover, we have explained the use of various common options with their practical examples too.

Install Wget Command:

The Wget command comes pre-installed on many Linux-based distributions, including Ubuntu. To verify either the Wget command is installed on your system or not, open up the terminal and execute the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_1.jpg" data-lazy- height="293" src="data:image/svg xml,” width=”801″>

The output confirms that the Wget command is installed on my system. However, if the Wget command is not installed, then you can install it on your Ubuntu and other Debian based systems with the command below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_2.jpg" data-lazy- height="458" src="data:image/svg xml,” width=”800″>

Syntax of Wget Command:

First, let’s discuss the syntax of the command. The syntax of the Wget command is as follows:

Multiple options can be used with the wget command. The url refers to the address of the file that we need to download.

Downloading the Files Using the Wget Command:

The simplest form of the Wget command is to use it without specifying any options. The Wget command downloads the files from the given url in the current working directory. For instance, let’s download the Skype Debian package with the appended Wget command below:

$ wget https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_3.jpg" data-lazy- height="426" src="data:image/svg xml,” width=”716″>

The Wget command sends the HTTP request and downloads the Debian package in the current directory.

In addition, it displays the progress bar, file size, download speed, etc.

Saving the Downloaded File with a Different Name:

Normally, the files are downloaded and saved with the original name. But, the Wget command allows us to rename the files before downloading using the –O option. After the –O option, we need to specify the filename:

$ wget -O Skype https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_4.jpg" data-lazy- height="556" src="data:image/svg xml,” width=”805″>

The Skype package name has changed to ‘Skype’.

Downloading the File in a Specific Directory:

As previously discussed, the files are saved in a current working directory. Nevertheless, the downloaded files can be saved in any other specific directory using the –p option. Let’s download the file and save it in the ‘Downloads’ directory with the below-given command:

$ wget -P /home/linux/Downloads https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_5.jpg" data-lazy- height="578" src="data:image/svg xml,” width=”810″>

The skypeforlinux-64.deb file is successfully downloaded and saved in the ‘Downloads’ directory.

Setting the Download Speed:

We can set a specific download speed for a file with the –limit-rate option. The downloading speed is measured in bytes/second by default. However, we can set the downloading speed in kilobytes (k), megabytes (m), and gigabytes (g).

$ wget –limit-rate=500k https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_6.jpg" data-lazy- height="491" src="data:image/svg xml,” width=”801″>

In the above-given command, the downloading speed is limited to 500 kilobytes per second.

Resuming an Interrupted Download:

If the downloading is interrupted, then you can easily resume it with the -c option.

I have interrupted a download by pressing ctrl-c. Let’s resume this download with the appended command:

$ wget -c https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_7.jpg" data-lazy- height="509" src="data:image/svg xml,” width=”805″>

Downloading the Multiple Files:

By using the Wget command, we can download multiple files as well. Store the file’s URLs in a text file whereas each URL starts on a new line. Use the -i option and specify the text file name next to it.

Let’s download the Linux Kernel 5.10 file.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_8.jpg" data-lazy- height="141" src="data:image/svg xml,” width=”894″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_9.jpg" data-lazy- height="575" src="data:image/svg xml,” width=”806″>

Both the Linux kernel files are downloaded successfully.

Downloading in the Background:

You can put your downloading process in the background with the -b option. Ideally, we do it while downloading the big file.

$ wget -b https://go.skype.com/skypeforlinux-64.deb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/How-to-Download-Files-from-the-Command-Line-Using-the-Wget-Command_10.jpg" data-lazy- height="112" src="data:image/svg xml,” width=”807″>

The downloading will be continued in the background.

Conclusion:

The Wget is a very useful command-line utility for downloading files from the command-line. It comes pre-installed on Ubuntu 20.04 and many Linux distributions. With the Wget command, we can download the files, save them with different names, save them in any other specified directory rather than the current working directory, and many more.

About the author

<img alt="Kamran Sattar Awaisi" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/02/echo/52E439DD556343299E3D211D5E577D28-150×150.jpg602938fc5648b.jpg" height="112" src="data:image/svg xml,” width=”112″>

Kamran Sattar Awaisi

I am a software engineer and a research scholar. I like to write article and make tutorial on various IT topics including Python, Cloud Computing, Fog Computing and Deep Learning. I love to use Linux based operating systems.