Ubuntu

How to Download Files from the Command Line Using the Wget Command?

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:

$ wget --version

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:

$ sudo apt install wget

Syntax of Wget Command:

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

$ wget [options] [url]

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

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

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

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

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

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.

$ wget -i file.txt

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

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

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.