Linux Command line offers more flexibility and control than GUI. A number of people prefer to use the command line over GUI because it is easier and quicker to use than GUI. Using the command line, it is easier to automate the tasks using one line. In addition, it utilizes fewer resources than GUI.
Downloading files is a routine task that is normally performed every day that can include file types like ZIP, TAR, ISO, PNG, etc. you can simply and quickly perform this task using the command line terminal. It requires only using your keyboard. So today, I will show you how you can download a file using the command line in Linux. There are normally two known ways to do this, that is using wget and curl utility. For this article, I am using Ubuntu for describing the procedure. But the same commands will work on other Linux distributions like Debian, Gentoo, and CentOS too.
Download files using Curl
Curl can be used to transfer data over a number of protocols. It supports many protocols including HTTP, HTTPS, FTP, TFTP, TELNET, SCP, etc. using Curl, you can download any remote files. It supports pause and resumes functions as well.
To get started with, first, you need to install the curl.
Launch command line application in Ubuntu that is Terminal by pressing the Ctrl+Alt+T key combinations. Then enter the below command to install curl with sudo.
$ sudo apt install curl
When prompted for a password, enter sudo password.
Once the installation is complete, enter the below command to download a file.
Download and save the file using the source file name
To save the file with the same name as the original source file on the remote server, use –O (uppercase O) followed by curl as below:
$ curl –O [URL]
Instead of -O, you can also specify, “–remote-name” as shown below. Both work the same.
Download and save the file with a different name
If you want to download the file and save it in a different name than the name of the file in the remote server, use -o (lower-case o) as shown below. This is helpful when the remote URL doesn’t contain the file name in the URL as shown in the example below.
$ curl –o [filename] [URL]
[filename] is the new name of the output file.
Download multiple files
To download multiple files, enter the command in the following syntax:
$ curl -O [URL1] -O [URL2]
Download files from an FTP Server
To download a file from FTP server, enter the command in following syntax:
$ curl -O ftp://ftp.example.com/file.zip
To download files from user authenticated FTP servers, use the following syntax:
$ curl -u [ftp_user]:[ftp_passwd] -O [ftp_URL]
Pause and resume download
While downloading a file, you can manually pause it using Ctrl+C or sometimes it automatically gets interrupted and stopped due to any reason, you can resume it. Navigate to the same directory where you have previously downloaded the file then enter the command in the following syntax:
$ curl –c [options] [URL]
Download files using Wget
Using wget, you can download files and contents from Web and FTP servers. Wget is a combination of www and the get. It supports protocols like FTP, SFTP, HTTP, and HTTPS. Also it supports recursive download feature. This feature is very useful if you want to download an entire website for offline viewing or for generating a backup of a static website. In addition, you can use it to retrieve content and files from various web servers.
Launch command line application in Ubuntu that is terminal by pressing the Ctrl+Alt+T key combinations. Then enter the below command to install wget with sudo.
$ sudo apt-get install wget
When prompted for a password, enter the sudo password.
Download file or webpage using wget
To download a file or a webpage, open the Terminal and enter the command in the following syntax:
$ wget [URL]
To save a single webpage, enter the command in the following syntax:
$ wget [URL]
Download files with a different name
If you want to download and save the file with a different name than the name of the original remote file, use -O (upper-case O) as shown below. This is helpful especially when you are downloading a webpage that automatically get saved with the name “index.html”.
To download a file with a different name, enter the command in the following syntax:
$ wget -O [filename] [URL]
Download files through FTP
To download a file from an FTP server, type the command in the following syntax:
$ wget [ftp_link]
To download files from user authenticated FTP servers, use the below syntax:
$ wget -u [ftp_user]:[ftp_passwd] -O [ftp_URL]
Recursively download files
You can use the recursive download feature to download everything under the specified directory whether a website or an FTP site. To use the recursive download feature, enter the command in the below syntax:
$ wget –r [URL]
Download multiple files
You can use wget to download multiple files. Make a text file with a list of file URLs, then use the wget command in the following syntax to download that list.
$ wget –i [filename.txt]
For instance, I have the text file named “downloads.txt” in which there is a list of two URLs that I want to download using wget. You can see my text file content in the below image:
I will use the below command to download the file links contained in the text file:
$ wget –i download.txt
You can see that it is downloading both links one by one.
Pause and Resume download
You can Press Ctrl + C to pause a download. To resume a paused download, go to the same directory where you were downloading the file previously and use –c option after wget as in the below syntax:
$ wget -c filename.zip
Using the above command, you will notice that your download has resumed from where it was paused.
So in this article, we have discussed the basic usage of two command-line methods using which you can download a file. One thing to Note that if you do not specify a directory while downloading a file, the files will be downloaded in the current directory in which you are working.