How to download file from a URL in Linux?


On Linux distributions that have GUI installed, you can download a file by just clicking on the downloading link in your browser. What if you don’t have GUI then how will you download a file on your system.

Linux provides wget and curl commands for this purpose. These commands provide various options that can be used for more useful things.

In this article, we will show you how to use these tools to download the file from a URL in Linux.

How to use wget to download a file

Wget is a command that retrieves content from a webserver. It supports downloading via HTTP, HTTPS, and FTP. The main features of the wget command include recursive download, conversion of links for offline viewing of local HTML, and support for proxies.

This command comes preinstalled on most of the distributions. If it is not on your system you can install it by using –

sudo apt install wget -y

The syntax wget command on Linux is –

wget [Options] [URL]

Where you can find a detailed list of options on the wget command’s man page. URL is the downloading link of a file or directory.

If no extra parameter is passed with the wget command it will download the file in your current working directory.

For example –

wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

As you can see in the image wget starts by resolving the domain’s IP address, then connects to the remote server and starts the transfer.

While downloading it shows a lot of information such as the progress of the download, transfer speed, and estimated time of completion.

Download a file with a different name

By using the option -O with this command, you can specify the name of the file.

For example –

wget -O linux-kernel-latest https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

Here downloaded file will be saved with the name linux-kernel-latest.

Download content recursively using wget

Using option -r with wget will direct this command to recursively download the content.

For example –

wget -r https://example.com

Download multiple files using the wget command

To download multiple files copy and save the downloading URL of each file in a text file and then use the given command to download them all.

wget -i download.txt

This command will download files from all the URLs given in the file download.txt.

Pause and resume the downloading

While downloading a file is in progress press Ctrl+c to pause it. To resume a paused download, go to the same directory where you were previously downloading the file use option –c with wget.

For example –

wget -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

This will start downloading the given file from where it was paused.

How to download the file from a URL using the curl command

The curl (or cURL) is another Linux command that allows the transfer of data using various network protocols. The name stands for “Client URL” it was first released in 1997.

This tool also comes preinstalled in many Linux distributions if it is not in your system you can use the given command to download it.

sudo apt install curl -y

Once gets installed you can start using it.

The syntax of this command is given below.

curl [option] [URL]

You can find the list of options on the man page of the curl command.

To download a file using the curl command you need to use.

For example –

curl -O https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

This will start by resolving the domain.

This also shows useful information such as total size, speed, time spent, and estimated time to complete.

Download and save the file with a different name

Mention the file name after the option -O to download a file with a different name.

curl -O linux-kernel-latest https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

This will save the downloaded file as linux-kernel-latest.

Download multiple files using curl

You can download multiple files by using the option -O, and URL. The syntax for of curl command to download multiple files is given below.

curl -O URL1 -O URL2 -O URL3 . . . .

This will download files from all the given URLs.

Pause and resume download in curl

While downloading a file is in progress press Ctrl+c to pause it. To resume a paused download, go to the same directory where you were previously downloading the file use option –c with curl.

curl -c https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz

This will start downloading the given file from where it was paused.

For more information, you can see the manual page of the curl command.

man curl

Conclusion

I hope you understand how to download a file from a URL in Linux. Now if you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.