Figuring out how to use the curl command in Linux?
We all are fond of the internet. Today, to even imagine living a life without the internet gives people the jitters. Whether it is social life, entertainment, education, or professional work, the internet has proved itself to be a very useful and powerful tool that now covers every walk of life.
There are commands that are specially designed to work together with the internet. One of those commands is curl which is used in the Linux operating system and its distros. It is used for transferring data between servers using certain support protocols such as HTTP, HTTPS, FTP, FTPS, SCP, etc.
In this guide, we will be discussing the curl command, its syntax, function, and different operators. It should prove useful to people who are trying to understand how to use the curl command in Linux and its distros.
So, without further ado, let’s get started!
The curl Command.
The purpose of the curl command has already been mentioned above. So, let’s discuss its syntax. Curl is used with different operators. Each operator serves a different purpose. For example, for downloading a file using the internet, you can use the “
-0” or “
-o” operator. In general, the syntax for curl is:
$ curl -operator <URL>
Next, we move towards discussing the different operations performed by curl and their respective operators. But before that, you should make sure that your Linux system has the curl package already been installed. The latest versions have it pre-installed. If you don’t have its package, follow these steps to download and install it.
- Open the Command Terminal.
- Once opened, type in the following command:
$ sudo apt update
- After executing the command above, type in:
$ sudo apt install curl
You can use the command above for installing curl on Ubuntu and Debian. In case you have Fedora or CentOS, use this command instead:
$ sudo yum install curl
Before going into further details of how to use the curl command in Linux, let’s talk about Virtual Network Computing or VNC. It’s a clever technology that allows users to access the peripheral devices attached to their computers remotely.
Download a File Using Curl.
To download a file using curl, use the operators “
-o” and “
Keep in mind that when you’re using “
-o”, you have to specify the name of the file you are going to download. In case you want to keep the name of the file the same as your URL, you should use the “
$ curl -0 <URL>
$ curl -o <URL>
You can also use “
-0” for downloading multiple files at once. Just follow this syntax.
$ curl -0 <URL1
-0 <URL 2>
-0 <URL3> and so on.
These are the two operators you can use to download files using curl.
Resume Downloading a File.
In case your download is paused or got interrupted due to some reason, and you want to resume downloading the file, you can do that using curl with the “
-C” operator. You will use “
-C” in combination with the download operators mentioned above. For example:
$ curl -C - -0 <URL>
Upon execution of the command, you should see that the download has now resumed.
Controlling the Transfer Rate.
If you want to control the data transfer rate between two network servers, you can do that using the “
-limit-rate” operator. The syntax for this would be:
$ curl -limit-rate <limiting value> <URL>
For example, if we want to limit the rate of transfer to 450KBs per second,
$ curl -limit-rate 450K <URL>
Obtaining HTTP Headers of a URL.
HTTP headers contain information such as the operating system being used, information about the online page requested to be accessed, type and capabilities of the web browser being used. We can access the HTTP headers of a URL with curl using the “
-I” operator together with “
--http2”. For example.
$ curl -I --http2 <URL>
And this is how you can make a request for HTTP headers.
Downloading Files From FTP Servers.
FTP servers or File Transfer Protocol servers are used to transfer files of any type from a server to a client. Using curl, we can achieve this by knowing the username and password for the FTP server. The operator we will use for this is “
-u”. The syntax for such an arrangement is as follows.
$ curl -u <username>:<password> FTP <URL>
Uploading Files To FTP Servers.
As we can download files from FTP servers, uploading files is also possible. “
-T” is the operator that will be used together with “
-u” to perform to complete this command. You also need to mention the name of the file you are going to upload. The syntax for this arrangement will be.
$ curl -T <filename> -u <username>:<password> FTP <URL>
This article was a guide on how to use the curl command in Linux and its distros. We discussed how to install the
$curl package on your system, the general syntax for curl, and the different operators used with curl and their respective operations.
The very basic uses of the curl command were discussed in this guide. Curl is a very powerful command and can be used to perform several other tasks you perform daily on the internet. The simple difference is that you will use the CLI instead of the GUI.
We hope that we were able to help you understand the basics of the curl command. As always, if you have any queries, please let us know in the comment section down below.
If this guide helped you, please share it. 🙂