How to use Wget to download files on Linux

If you know the direct download link of the file you want to download, you can download it from the console with the help of the wget command without using any additional programs or a browser.

GNU/Linux has many practical uses. You can easily process all your transactions through Terminal. If you have read or watched Linux related video tutorials, you must have come across the wget command. It is very easy to use and works by taking parameters.

For example, if you know the direct download link of the file you want to download, you can download it from the console with the help of the wget command without using any additional programs or a browser.

Here's everything you need to know about the wget command including some practical examples.

Quick start Guide

  1. To download a single file, find the file link > apply the wget link_download command.
  2. To download multiple files, save the links you want to download in a file, and then use the -i parameter with the wget command.
  3. To download a file to a custom location, create the directory where you want to save the file, then use the -P flag with the wget command and specify the full path to the desired location.
  4. To specify a custom filename, create a new directory, load the file with the custom name with the wget -O parameter.
  5. To resume interrupted downloads with Wget, use wget -c link_download.
  6. Limit Wget's download speed with wget --limit-rate link_download speed.
  7. To download files in the background, use the -b parameter.

Detailed instructions

Download a single file

This is one of the most basic uses of the wget command. The intent here is to download a single file into the system using a known destination link. The wget command used for this is:

wget https://download.aircrack-ng.org/aircrack-ng-1.7.tar.gz

Picture 1 of How to use Wget to download files on Linux

As shown in the image, you can download the file with the wget command and find where to download it with ls -l.

Batch download of files

Multiple files from links stored in a text document can be downloaded at once using the -i parameter with the wget command.

For example, you want to download all PDF files at a certain address at once. To do this, you need to save the download links of these PDF files in a text document. You can do this by creating a file named my_pdfs with the vim my_pdfs command and adding the necessary links to the file.

Picture 2 of How to use Wget to download files on Linux

Let's download the PDF formats of Google Cloud documents as an example. Save links to PDF files in a file and use the following command to download them:

wget -i my_pdfs

Picture 3 of How to use Wget to download files on Linux

After this step, you can view the downloaded files by running:

ls -l

Picture 4 of How to use Wget to download files on Linux

Download by specifying a custom location

If you want the file to download to a special location on your system, you need to use the -P flag with the command:

wget -P /path/to/dir filelink

You can see this in the example below. Likewise, try downloading the file aircrack-ng and this time specifying an address. For example, you can create a folder Myfile to store downloaded files.

wget -P Myfile https://download.aircrack-ng.org/aircrack-ng-1.7.tar.gz

Picture 5 of How to use Wget to download files on Linux

To download the file to the desired location, you must specify the full path to the directory. You can also run the following ls -l command to make sure the file is actually where you want it to be.

Download by specifying a custom filename

With the wget -O parameter, you can name the file you want to download and download it to any location you want. To avoid confusion, create a new oParameter folder and try to download your aircrack-ng file to this folder by giving it the name you want, in this case aircrack.

wget -O oParameter/aircrack https://download.aircrack-ng.org/aircrack-ng-1.7.tar.gz

Picture 6 of How to use Wget to download files on Linux

After Wget has finished downloading the file named "aircrack" and saving it to the /oParameter directory, you can confirm this with the command ls -l.

Also, if you want to change the name of the downloaded file without changing its location, just specify the new filename without specifying any location. For example, you can change the name of the file to download using the wget new_name file_link command. Since you don't specify any location, it will automatically download at your current working directory.

wget myfilename https://download.aircrack-ng.org/aircrack-ng-1.7.tar.gz

Picture 7 of How to use Wget to download files on Linux

Resume interrupted downloads with Wget

Failed download is one of the most common problems when downloading large files. In such cases, you can continue the download and get the rest of the file.

You can use the -c parameter with the wget command to re-download the interrupted file. Therefore, by using wget -c download_link, if the file is not completely downloaded, you have the opportunity to continue from where it left off instead of re-downloading it from the beginning. This is very practical, especially for large files.

To better understand this, first create a folder called Resume on the desktop. Access this folder using Terminal with the cd command and try to download the aircrack file you used in the other examples here. Then, interrupt this download with the keyboard combination Ctrl + Z.

Picture 8 of How to use Wget to download files on Linux

As you can see, 19% of the files have been downloaded, occupying 1645946 bytes. Now use the -c parameter in the same way and try to resume the download.

Picture 9 of How to use Wget to download files on Linux

As you can see, the download is complete. Thus, there is no need to delete the file and re-download it from the beginning. This is just a small file for example. But for very large files, you can save time by using Wget.

Wget download speed limit

If you want, you can limit the download speed for the file. To set this limit, you can use the following command:

wget --limit-rate 300K https://download.aircrack-ng.org/aircrack-ng-1.7.tar.gz

This command will limit the download speed to 300KB per second.

Picture 10 of How to use Wget to download files on Linux

You can try different speeds by varying the value of 300K.

Download files in the background

You can download files in the background with the -b parameter. This is most useful when you are busy with many tasks. Also, if you want to find out the result of the download, you can simply check the wget-log file located in the same location as the downloaded file.

Picture 11 of How to use Wget to download files on Linux

Update 18 June 2022
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile