What Is Curl Command in Linux and The way to Importance It

Shopper URL or cURL is a knowledge switch instrument in Linux that may produce other types of requests from the customer aspect to any far flung server. With the curl command, you’ll be able to produce easy and sophisticated requests to the server to get admission to the vital data. On this article, we give an explanation for what’s the curl command and its other significance instances in Linux so that you can harness its energy.

What Is the curl Command in Linux

cURL stands for ‘Client URL’ and is old to switch information to and from a far flung server the use of various kinds of community request varieties. It’s necessarily made up of 2 parts – the command order instrument “curl” and the “libcurl” library.

Each cURL and curl are once in a while interchangeably old, however they’ve some variations — cURL is an entire information switch software that may be old with other languages. At the alternative hand, curl is a command order instrument that makes use of the libcurl library to ship and obtain information for your Linux distro.

curl Command: Syntax and Choices

Now that you realize what’s curl, it’s while to know the syntax of the curl command in Linux:

curl <choices> <url>

We now have indexed probably the most usual choices you’ll be able to significance with the curl command right here, however you’ll be able to take a look at alternative cool Linux instructions by means of the related article.

Choices Description
-# Displays a walk bar when downloading a record the use of curl
-o Saves the downloaded record with a special identify specified at the shopper’s device
-O When old, it’s going to save the downloaded record with the similar identify because the <url>
-T Old to add a record to an FTP server
-x Accesses the <url> by means of a proxy server
-w Produce curl show data on stdout next a finished switch

The way to Importance curl Command in Linux (6 Examples)

Now that you’ve got a ordinary figuring out of the syntax and choices to significance with the curl command, allow us to see some sensible examples of the use of the curl command.

1. Preserve a Record the use of the curl command

While you significance the curl command with none <choices>, it merely prints the supply code of the internet web page you’re sending the request to. To avoid wasting this output to a record on your Linux record device, significance the curl command with the -o flag:

curl <choices> -o <file_name_to_save> <url>

As an example:

curl -o index.html https://test.rebex.net/

2. Checking out If a Server Is To be had or No longer

With the -I flag, you’ll be able to significance the curl command in Linux to test whether or not a server is to be had or no longer. The syntax is:

curl <choices> -I <url>

Right here, test for the primary order of the reaction. In case you get “200 OK” within the reaction, it implies that the server is operating wonderful future any alternative reaction implies the server isn’t operating correctly. As an example, to test if take a look at.rebex.web is to be had or no longer, significance refer to syntax:

curl -I https://test.rebex.net/
using the curl command in Linux to check if a server is available or not

3. Getting access to Cookies with curl Command

Every time you seek advice from a URL, some data will get saved on your device, which is after old while you seek advice from later while the similar URL. So, simply significance the --cookie-jar flag with the curl command to get admission to the cookies saved on your Linux record device for the given <url>:

curl <choices> --cookie-jar <file_to_write_cookies> <url>

As an example, right here’s the command to collect the entire cookies of https://test.rebex.net/ within the cookies.txt record:

curl --cookie-jar cookies.txt https://test.rebex.net/
saving the cookies in a file with curl command in Linux

4. Obtain Information from FTP Server the use of curl

Usually, when getting access to a conserve FTP server, you wish to have to go into the password each and every while you plank in to the server. However with curl, you’ll be able to immediately specify the username and password with refer to syntax:

curl -u <username>:<password> -O <url>

As an example, you’ll be able to significance refer to command to obtain the readme.txt record from the take a look at.rebex.web FTP server with “demo” because the username and “password” because the password:

curl -v -u demo:password -O ftp://take a look at.rebex.web/readme.txt
downloading a file from a ftp server

5. Surroundings Person Agent Price with curl

Every time you produce a request to a server from any browser, the request frame accommodates a “user-agent” argument that specifies which browser model you’re the use of to ship the request.

With the curl command, you’ll be able to spoof the instrument and browser model you’re the use of with the –user-agent flag. As an example, if you wish to significance Mozilla model 4.73 on an X11 Linux device with the kernel model 2.2.15 and i686 structure to check.rebex.web, you must significance refer to command:

curl --user-agent "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" take a look at.rebex.web
changing the user agent to Mozillia in Linux 2.2.15 with curl command

6. Test Server Reaction Week

With some smart significance of the choices -w, -s, and -o, you’ll be able to significance the curl command in Linux to test the reaction while of the server. The syntax is:

curl -w "%{time_total}n" -o /dev/nil <url>

Right here, the -w is old to jot down out the price of time_total variable to output display screen, -o to avoid wasting the output to /dev/nil record. As an example, to test the reaction while of the web page “test.rebex.net” the use of this command. The highlighted division displays the reaction while of the server in seconds.

curl -w "%{time_total}n" -o /dev/nil take a look at.rebex.web
checking the response time of a server

Leave a Comment