Wget and Curl are among the wide range of command line tools that Linux offers for the downloading of files. Both offer a huge set of features that cater to different needs of the users. If users simply want to download files recursively, then Wget would be a good choice. In this tutorial, we will discuss how to use curl command and download files using curl options on Linux. The curl package is pre-installed on most Linux distributions today. The -V or -version options will return the version, and also the supported protocols and features in your current version.
In recent years, technology has evolved and grown significantly, highlighting the changes taking place in the digital world. These technological advancements have led to the creation of so many extraordinary tools and softwares that have significantly aided in making our lives easier.Linux, a Unix based open-source operating system, is one example of such a software that only a few years back, didn’t have the specs to be used in desktops and as a result, was mainly considered for server development. However, with time, it has rapidly evolved, becoming a reliable and powerful operating system, which in turn has led to it gaining the attention of a large number of users.
The Command Line tool provided by Linux is one of its most powerful features that it offers to users and is also what makes it so fascinating and amazing to use. A command line is simply a text-based interface that takes in commands and forwards them to the OS which runs them. It is due to this flexible nature of it that it has gained an edge over the Graphical User Interface (GUI) and as a result, many users have switched to the Command Line for doing various tasks, one of which is the downloading of files.
Hence today we’ll be looking at two different ways on how to download files on Linux using the Command Line tool.
Downloading Files using Wget
One of the most popular command line tools for downloading files from the internet is Wget. Wget is a pretty versatile tool that supports multiple protocols such as HTTP, HTTPS and FTP and allows one to download multiple files and directories. It also provides users with a variety of features ranging from recursive downloading to playing and pausing the downloads as well as limiting its bandwidth.
Moreover, it is cross-platform which gives it quite the edge over many other command line downloaders as well as graphical downloaders.
How to Install Wget?
Wget usually comes pre-installed with most of the Linux Distributions. However, if a user is in possession of a system without Wget being installed, then the user needs to open the command line through either Ubuntu Dash or Ctrl+Alt+T shortcut and enter the following command:
It is to be noted that the command given above is for only Debian based Linux systems such as Ubuntu. If a user has a Red Hat Linux system such as Fedora, then the user needs to enter the following command into the command line:
Features of Wget
As mentioned before, Wget has multiple features incorporated inside of it. The most basic operation that Wget offers to users is downloading files by simply using its URL. This can be done by inputting the following command into the terminal:
Let us show an example to further clarify this. We will be downloading a simple image in the png format from the internet. See the image below for better understanding:
Wget also allows users to download multiple files from different URLs. This can easily be done by the following command:
Once again, we can show this using an example. We will be downloading two HTML files from two different websites. For better understanding, please look at the image below:
We can also change the name of the file from its original using the following command:
Here filename refers to the name that you want to address the file as. Using this, we can also change the type of the file. This is shown in the image below:
Wget also allows users to recursively download their files which is basically downloading all the files from the website under a single directory. This can easily be done by the following command:
For more information regarding Wget, users can input the following command into the terminal to get access to all the Wget commands that appear to be available:
Downloading Files using Curl
Curl is another command line tool that can be used to download files from the internet. Unlike Wget, which is command line only, features of Curl are powered by libcurl which is a cross-platform URL transfer library. Curl not only allows downloading of files but can also be used for uploading and exchanging of requests with servers. Curl also has a much larger support range for protocols including the important ones such as HTTP, HTTPS, FTP, SFTP etc. However, Curl does not support recursive downloads which Wget offers.
How to Install Curl?
Similarly, like Wget, Curl comes pre-installed with most of the Linux Distributions. This can simply be checked by running the following command:
However, if a user is in possession of a system without Curl being installed, then the user needs to open the command line through either Ubuntu Dash or Ctrl+Alt+T shortcut and enter the following command:
It is to be noted that the command given above is for only Debian based Linux systems such as Ubuntu. If a user has a Red Hat Linux system such as Fedora, then the user needs to enter the following command into the command line:
Features of Curl
Just like Wget, Curl has multiple features incorporated inside of it. The most basic is its ability to allow users to download files from a single URL from the internet. This can be done by inputting the following command into the terminal:
For better understanding, we will be downloading a simple image in the png format from the internet just like in the case of Wget.
Curl also allows users to change the filename and the type of the file. This can be done by the following command:
In the image above, we took a png file originally named pancake1.png and converted it to a zip file with the new name p.zip.
Just like in the case of Wget, Curl allows users to download multiple files using a number of URLs from the internet. This can easily be done by the following command:
For our example, we will use curl to download a jpg file and a png file from the internet. Results are shown in the image below:
A pretty amazing feature that Curl provides to its users is its ability to monitor the progress of the download of the file. This can be done by the following command:
For more information regarding Curl, users can input the following command into the terminal to get access to all the Curl commands that appear to be available:
Best Command Line Method to Download Files
Wget and Curl are among the wide range of command line tools that Linux offers for the downloading of files. Both offer a huge set of features that cater to different needs of the users. If users simply want to download files recursively, then Wget would be a good choice. If users are looking to interact with the server or download a file built under a protocol that Wget doesn’t support, then Curl would be a better alternative.
Curl is a popular command-line tool used for downloading files from the Internet. It is a lightweight tool that is available on any UNIX system. Curl supports a wide range of protocols, for example, HTTP, HTTPS, FTP, FTPS, SFTP, etc. If no protocol is specified, curl defaults to HTTP. The functionalities of curl come from libcurl.Curl started its journey back in the mid-1990s when the Internet was still a new thing. Daniel Stenberg, a Swedish programmer, started the project that eventually became curl. He aimed to develop a bot that would download currency exchange rates from a webpage periodically and provide Swedish Kronor equivalents in USD to IRC users. The project was successful and, thus, curl was born.
Over time, curl was further improved with the addition of new internet protocols and features. In this guide, check out how to use curl to download a file.
Installing curl
Today, you will find curl pre-installed in most of the Linux distros. Curl is quite a popular package and is available for any Linux distro. However, there is no guarantee that curl is currently installed in your distro.
Run the command according to your distro type to install curl on your system.
To install curl on Debian/Ubuntu and derivatives, enter the following:
To install curl on RHEL, CentOS, Fedora, and derivatives, enter the following:
To install curl on OpenSUSE and derivatives, enter the following:
To install curl on Arch Linux and derivatives, enter the following:
Curl is open-source software. You can grab the curl source code and compile it manually. However, this process is more complex and should be avoided if you intend to use curl for more than testing or redistributing/packaging.
The following process was demonstrated in Ubuntu. For an in-depth guide on compiling curl, check out the official curl documentation.
Download the curl source code here. I have grabbed the latest version of the curl source code. At the time of writing this article, the latest version is curl v7.72.0.
Extract the archive.
Run the configuration script.
Start the compilation process.
Finally, install the curl program that we just compiled.
Using curl
To demonstrate the usage of the curl program, first, we need a dummy file to download. Any online file will work for this, as long as you have the direct download link. For this guide, I will use the small file provided by think broadband.
Curl Version
Check out the version of curl by entering the following:
Download File Using curl
This is a very basic way of using curl. We will download the dummy file. Here, the “-O” flag tells curl to download and save the file in the current directory.
To download and save the file with a different file name, use the “-o” flag. With this flag, the file will be downloaded and saved at the current working directory.
Download Multiple Files
Need to download multiple files? Follow the command structure shown below. Use either “-o” or “-O” as necessary.
Progress Bar
By default, curl does not show any progress bar. To enable the progress bar, use the “-#” flag.
Silent Mode
If you want curl to print no output, use the “–silent” flag.
Speed Limit
Curl allows you to limit the download speed. Use the “–limit-rate” flag, followed by the bandwidth limit, to do so. Here, the download speed is limited to 1mb.
Manage FTP Server
It is also possible to manage an FTP server using curl. Assuming that the FTP server is protected, you will need to use the “-u” flag, followed by the username and password. If no file is specified, curl will print a list of all the files and directories under the user’s home directory.
Downloading files from an FTP server is like the method shown before. However, assuming the FTP server requires user authentication, use the following command structure:
To upload a file to the FTP server, use the following command structure:
User Agent
In certain situations, the URL that you are trying to access may be blocked due to a lack of a proper user agent. Curl allows you to define the user agent manually. To do so, use the flag “-A,” followed by the user agent. As for the user agent, you can use the User Agents randomizer. If you want a custom user agent, then you can find one from WhatIsMyBrowser.
Final Thoughts
Despite it being a simple and lightweight tool, curl offers tons of features. Compared to other command-line download managers, like wget, curl offers a more sophisticated way of handling file downloads.
For in-depth information, I always recommend checking out the man page of curl, which you can open with the following command:
Check out some of the best download managers for Linux here.
Linux Command Line To Download File
Happy computing!