Curl Command in Linux with Examples

Please assist us proceed to give you free, high quality tutorials by turning off your advert blocker on our web site.

curl is a command-line utility for transferring information from or to a server designed to work with out person interplay. With curl, you possibly can obtain or add information utilizing one of many supported protocols together with HTTP, HTTPS, SCP, SFTP, and FTP. curl offers a variety of choices permitting you to renew transfers, restrict the bandwidth, proxy help, person authentication, and rather more.

On this tutorial, we’ll present you methods to use the curl software by sensible examples and detailed explanations of the commonest curl choices.

Putting in Curl

The curl bundle is pre-installed on most Linux distributions at this time.

To test whether or not the Curl bundle is put in in your system, open up your console, kind curl, and press enter. When you’ve got curl put in, the system will print curl: strive ‘curl –help’ or ‘curl –manual’ for extra data. In any other case, you will note one thing like curl command not discovered.

If curl isn’t put in you possibly can simply set up it utilizing the bundle supervisor of your distribution.

Set up Curl on Ubuntu and Debian

sudo apt replace
sudo apt set up curl

Set up Curl on CentOS and Fedora

sudo yum set up curl

Find out how to Use Curl

The syntax for the curl command is as follows:

In its easiest kind, when invoked with none choice, curl shows the desired useful resource to the usual output.

For instance, to retrieve the homepage you’d run:


The command will print the supply code of the homepage in your terminal window.

If no protocol is specified, curl tries to guess the protocol you need to use, and it’ll default to HTTP.

Save the Output to a File

To save lots of the results of the curl command, use both the -o or -O choice.

Lowercase -o saves the file with a predefined filename, which within the instance beneath is vue-v2.6.10.js:

curl -o vue-v2.6.10.js https://cdn.jsdelivr.internet/npm/vue/dist/vue.js

Uppercase -O saves the file with its authentic filename:

curl -O https://cdn.jsdelivr.internet/npm/vue/dist/vue.js

Obtain A number of recordsdata

To obtain a number of recordsdata without delay, use a number of -O choices, adopted by the URL to the file you need to obtain.

Within the following instance we’re downloading the Arch Linux and Debian iso recordsdata:

curl -O

Resume a Obtain

You may resume a obtain through the use of the -C – choice. That is helpful in case your connection drops through the obtain of a giant file, and as an alternative of beginning the obtain from scratch, you possibly can proceed the earlier one.

For instance, if you’re downloading the Ubuntu 18.04 iso file utilizing the next command:

curl -O

and all of the sudden your connection drops you possibly can resume the obtain with:

curl -C – -O

HTTP headers are colon-separated key-value pairs containing data similar to person agent, content material kind, and encoding. Headers are handed between the shopper and the server with the request or the response.

Use the -I choice to fetch solely the HTTP headers of the desired useful resource:

curl -I –http2

Take a look at if a Web site Helps HTTP/2

To test whether or not a selected URL helps the brand new HTTP/2 protocol, fetch the HTTP Headers with -I together with the –http2 choice:

curl -I –http2 -s | grep HTTP

The -s choice tells curl to run in a silent (quiet) and conceal the progress meter and error messages.

If the distant server helps HTTP/2, curl prints HTTP/2.0 200:

HTTP/2 200

In any other case, the response is HTTP/1.1 200:

HTTP/1.1 200 OK

When you’ve got curl model 7.47.Zero or newer, you do not want to make use of the –http2 choice as a result of HTTP/2 is enabled by default for all HTTPS connections.

Observe Redirects

By default, curl does not comply with the HTTP Location headers.

If you happen to attempt to retrieve the non-www model of, you’ll discover that as an alternative of getting the supply of the web page you will be redirected to the www model:


The -L choice instructs curl to comply with any redirect till it reaches the ultimate vacation spot:

curl -L

Change the Consumer-Agent

Generally when downloading a file, the distant server could also be set to dam the Curl Consumer-Agent or to return totally different contents relying on the customer machine and browser.

In conditions like this to emulate a distinct browser, use the -A choice.

For instance to emulates Firefox 60 you’d use:

curl -A “Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0”

Specify a Most Switch Charge

The –limit-rate choice permits you to restrict the info switch fee. The worth might be expressed in bytes, kilobytes with the okay suffix, megabytes with the m suffix, and gigabytes with the g suffix.

Within the following instance curl will obtain the Go binary and restrict the obtain pace to 1 mb:

curl –limit-rate 1m -O

This feature is beneficial to forestall curl consuming all of the out there bandwidth.

Switch Information by way of FTP

To entry a protected FTP server with curl, use the -u choice and specify the username and password as proven beneath:


As soon as logged in, the command lists all recordsdata and directories within the person’s house listing.

You may obtain a single file from the FTP server utilizing the next syntax:


To add a file to the FTP server, use the -T adopted by the identify of the file you need to add:

curl -T newfile.tar.gz -u FTP_USERNAME:FTP_PASSWORD

Ship Cookies

Generally chances are you’ll must make an HTTP request with particular cookies to entry a distant useful resource or to debug a difficulty.

By default, when requesting a useful resource with curl, no cookies are despatched or saved.

To ship cookies to the server, use the -b change adopted by a filename containing the cookies or a string.

For instance, to obtain the Oracle Java JDK rpm file jdk-10.0.2_linux-x64_bin.rpm you will must cross a cookie named oraclelicense with worth a:

curl -L -b “oraclelicense=a” -O

Utilizing Proxies

curl helps several types of proxies, together with HTTP, HTTPS and SOCKS. To switch information by a proxy server, use the -x (–proxy) choice, adopted by the proxy URL.

The next command downloads the desired useful resource utilizing a proxy on port 8888:

curl -x

If the proxy server requires authentication, use the -U (–proxy-user) choice adopted by the person identify and password separated by a colon (person:password):

curl -U username:password -x


curl is a command-line software that permits you to switch information from or to a distant host. It’s helpful for troubleshooting points, downloading recordsdata, and extra.

The examples proven on this tutorial are easy, however display essentially the most used curl choices and are meant that can assist you perceive how the curl command work.

For extra details about curl go to the Curl Documentation web page.

When you’ve got any questions or suggestions, be at liberty to depart a remark.


Germany Devoted Server

Leave a Reply