Working in a Linux command line gives you more flexibility and control as compared to GUI. Command-line has many uses and is extensively used in server administration. You can automate the task using the command line and also it utilizes fewer resources than GUI. Downloading a file using the command line is also easier and quicker as it requires only a single command as compared to GUI which mostly requires long steps procedure.

In this article, we will explain how to download a file using the Linux command line using two different utilities. Both are free utilities for non-interactive download of files from web. These utilities working in the background even when you are not logged in.

We will use Debian 10 for describing the procedure mentioned in this article.

Method #1 Download files using Curl

Curl is a command-line utility that is used to transfer files to and from the server. We can use it for downloading files from the web. It is designed in such a way that you can run it without a user interaction. It supports various protocols including HTTP, HTTPS, TELNET, SCP, FTP, etc. It is not by default installed in Debian OS. Therefore, we have to install it first. To do so, follow the below steps:

Install Curl

Launch the Terminal application in Debian. For that, go to the Activities tab in the top left corner of the desktop. Then in the search bar, type terminal. When the Terminal icon appears, click on it to launch it.

In the Terminal, type the following command to switch to the superuser account.

$ su

When prompted for the password, enter superuser password.

Then run the following command in Terminal to install Curl utility.

$ apt install curl

Installing curl on Debian

Once the installation is completed, we can use the Curl for downloading files.

General syntax of CURL :

To download files using Curl, use the following syntax in Terminal:

$ curl [options] [URL]

Using the [options] parameter, you can specify various functions, for instance, save the download with a specific name, resume a download, specify transfer rate and much more.

Using the [URL] parameter, you can specify the URL of the remote server.

Download and save the file using the source file name

To download and save the file with the same name as the source file name, use the following syntax:

$ curl –O [URL]

An example of this would be:

$ curl -O https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

It will save the downloaded file as debian-10.0.0-amd64-DVD-1.iso.

Download and save the file using the source file name using curl

Alternatively, you can also specify, “–remote-name” instead of –O to save the file as the remote file name.

Download and save the file with a different name

To download and save the file with the different name as the source file name, use the following syntax:

$ curl [URL] –o [filename]

In the [filename] parameter, specify a new name for the downloaded file.

An example of this would be:

$ curl https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso -o debian.iso

It will save the downloaded file as debian.iso.

Download and save the file with a different name

Download multiple files simultaneously

Instead of downloading multiple files one by one, you can download all of them simultaneously by running a single command. To download multiple files at the same time, use –O followed by the URL to the file that you wish to download.

Use the following syntax for this purpose:

$ curl -O [URL1] -O [URL2]

An example of this would be:

$ curl -O https://www.debian.org/doc/manuals/debian-reference/debian-reference.en.pdf -O https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

The above command will download both files.

Download multiple files simultaneously with curl

There is an alternative way of doing this. Specify the list of URLs in a file, then use the Curl command along with xargs in the following syntax:

$ xargs –n 1 curl –O < [filename]

An example of this would be:

$ xargs –n 1 curl –O < files.txt

Our files.txt file contains two URLs:

Download all urls from a text file

The above Curl command will download all the URLs specified in the files.txt file.

Result downloading files

Download files from an FTP Server

We can also download files from FTP server using the Curl utility. To do so, run the command in Terminal using the following syntax:

$ curl -u ftp_user:ftp_pass -O ftp://ftp_url/file_name.zip

ftp_user and ftp_pass parameters are used to specify FTP login credential. However, you can skip these in case of anonymous FTP connection.

Pause and resume download

You can also resume a download that has been paused manually or due to some other reason. To manually pause a download, use Ctrl+C.

To resume a paused download, navigate to the directory where you have previously downloaded the file, then use the following syntax to resume it.

$ curl –c- [options] [URL]

An example of this would be:

To resume a paused downloaded file debian-10.0.0-amd64-DVD-1.iso file, we have used this command:

$ curl –c https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

From the following output, you can see that it has resumed the download.

Download files from FTP server

Download files using Wget

Similar to Curl, there is another command-line utility Wget that can be used to download files and content from the web. Wget is a combination of the World Wide Web and the word get. It supports protocols like FTP, SFTP, HTTP, and HTTPS. Also, it supports recursive downloading that is very useful if you want to download a whole website for offline viewing or for creating a backup for static website.

Install Wget

If wget is not already installed on your system, you can install it by following the below steps:

Launch the Terminal application in the same way as discussed earlier in this article. In the Terminal, type the following command to switch to the super user account.

$ su

When prompted for the password, enter superuser password.

Then run the following command in Terminal to install Wget utility.

$ apt-get install wget

Install wget on Debian 10

General syntax of Wget

To download a file using Wget, use the following syntax:

$ wget [URL]

Download and save the file using the source file name

Using the above syntax for downloading a file without any argument will save the file with the same name as the source file. An example of this would be to download a debian-10.0.0-amd64-DVD-1.iso file.

$ wget https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

It will save the download as a debian-10.0.0-amd64-DVD-1.iso.

Download and save the file using the source file name using wget

Download and save the file with a different name

To download and save the file with the different name as the source file name, use the following syntax:

$ wget –O debian10 https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

It will save the download as a debian10.

Download and save the file with a different name using wget

Download files through FTP

To download files from user authenticated FTP servers, use the below syntax:

$ wget -u [ftp_user]:[ftp_pass] -O [ftp_URL]

ftp_user and ftp_pass parameter are used to specify FTP login credential. However, you can skip these in case of anonymous FTP connection.

Download multiple files

To download multiple files using Wget, create a text file with a list of files URLs and then use the below syntax to download all files at simultaneously.

$ wget –i [filename.txt]

For instance, we have created a text file files.txt that contains two URLs as shown in the image below.

File that contains multiple url's

Then we have run the following command:

$ wget –i files.txt

Download all files from url file

Running the above command will automatically download both the URLs contained in the files.txt.

Pause and Resume download

To resume a paused download, navigate to the directory where you have previously downloaded the file, then use the following syntax to resume it.

$ wget -c [filename]

An example of this would be to resume a previously paused debian-10.0.0-amd64-DVD-1.iso file by running the following command.

$ wget –c https://gemmei.ftp.acc.umu.se/debian-cd/current/amd64/iso-dvd/debian-10.0.0-amd64-DVD-1.iso

wget: Pause and Resume download

Recursively download files

Wget supports recursive downloading that is a major feature that differs it from Curl. Recursive download feature allows downloading of everything under a specified directory.

To download a website or FTP site recursively, use the following syntax:

$ wget –r [URL]

An example of this would be to download the following entire site.

$ wget –r https://vitux.com/debian

Recursively download files using wget

So, in this article, we have learned two different non-interactive command line utilities that let you download files directly from the command line. Both utilities comes in handy and servers a similar purpose. I hope it will be helpful whenever you need to download a file from the internet.

How to Download Files on Debian using curl and wget on the Command Line