The Linux curl command is a utility that transfers data to and from a server over the internet. With the curl command, you can download files on the internet over a wide array of supported protocols such as SCP, FTP, HTTP, and HTTPS just to mention a few. Among the options provided by the Linux curl command, this includes proxy support, bandwidth limiting, and the ability to resume file downloads in case of downtime. In this guide, we look at the curl command and provide some of the example usages.
Curl command takes the syntax shown below:
Surprisingly, the Linux curl command does not come pre-installed in all Linux distributions. Just to verify if curl is installed, you can run the following command to check the curl version
From the output, I’m using curl version 7.68.0
If curl is not installed, you may encounter the error curl command not found. To address this, you need to install the curl command-line utility.
So, here’s how you can go about the installation.
Install Curl on Ubuntu / Debian Distributions
If your Debian or Ubuntu distro doesn’t come with curl, install it as follows
$ sudo apt-get install curl (For older versions of Ubuntu)
Install Curl on RHEL/CentOS Distributions
If you are running RHEL or CentOS, install curl as follows:
Install Curl on Fedora
For Fedora, install curl as follows:
Download a File Using the Curl Command
In its basic form, the curl command is used to download files over the internet with the -O option.
The -O option displays the progress meter of a file download. Also, it saves the file in its original name.
For example, to download the latest WordPress compressed file, run the command:
Download Multiple Files Using the Curl Command
The curl command also gives you the option of downloading multiple files in one command using the syntax shown below.
For instance, to download the compressed WordPress file and the Linux kernel tarball in one command, run the command:
Resume an Interrupted File Download
If you are downloading a file and your connection suddenly drops, don’t fret. You can pass the -C option to resume the file download.
If, for instance, you were downloading a file over the internet as follows,
In the event that the connection drops, you can easily resume the download with the -C option.
Limit the Download Rate
Curl command can consume significant amounts of your bandwidth. The speed is usually in bytes/seconds without any arguments. However, you can cap the data transfer rate by using the –limit-rate option followed by the value as follows:
Kilobytes – k or K
Megabytes – m or M
Gigabytes – g or G
For example, the command below limits the download rate of the Go binary file to 500 kilobytes/sec.
Grab HTTP Headers of a URL
HTTP headers form the core part of HTTP requests and contains information about the requested webpage such as the type of the web server, the version of HTTP being used, content type, content length and so much more.
The -I option lets you print out the HTTP headers using the syntax as follows:
Transfer Files Using FTP Protocol
Lastly, the curl command provides you with the ability to download a file from an FTP server with authentication using the -u option.
To upload a file to the FTP server, use the -T option as shown:
As you have observed, the curl command is quite a versatile command-line utility that facilitates file transfer over various protocols. These are just a few examples. For more options, head over to the documentation page.