Curl Command in Linux Terminal with Examples

Curl Command in Linux Terminal with Examples

In this article we are going to shows how to use curl command in Linux. If you want to learn about curl command in Linux with Examples then this post is ideal for you.

In Linux computing, curl is a command line utility that is used for transferring data from or to a server using any of the supported protocols including HTTP, HTTPS, FTP, IMAP, POP3, SCP, SFTP, SMTP or FILE .

curl also used to download or upload data with number of options allowing you to resume transfers, limit the bandwidth, proxy support, user authentication and many more.

It is designed to work without user interaction and can also transfer multiple file at once.

How to Use curl command in Linux

At this time, curl package comes pre-installed with most of Linux distributions. But if it is not installed in your Linux system then you can follow bellow steps to install in your system:

Install Curl on Ubuntu and Debian

sudo apt install curl

Install Curl on CentOS and Fedora

sudo yum install curl

Syntax of Curl Command

In the Ubuntu Linux, the basic syntax of the Curl command is show as below:

curl [options] [URL...]

Here,


Examples of Curl Command:

When you run the curl command without any options then it will display the source code of the given URL.

$ curl www.example.com

When you run the command above, it will display the content of the www.example.com in your terminal.


Download a file using the curl command

Use the -o or -O option to download or save the output of the curl command.

-o (lowercase): This option saves the downloaded file with the name provided in the parameters:

$ curl -o [file_name] [URL...]
$ curl -o newfilename.zip http://wwww.example.com/originalfilename.zip

-O (uppercase) : This option saves the downloaded file with the original file name:

$ curl -O http://www.example.com/originalfilename.zip

Resume Download

Use -C - option to resume a download file which is stopped due to some reason. This option very useful when you are going to download a large file or your connection was interrupted during downloading:

$ curl -C - [URL...]
$ curl -C - -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso

Send Specified Data in POST Request

Use --data option with curl command to send specified data in POST Request:

$ curl --data "username=xyz&password=123" https://www.example.com/insert

Get the HTTP Headers of a URL with Curl command

Use the -I option with the curl command to fetch the HTTP headers of the specified URL:

$ curl -I --http2 https://www.google.com/

Follow Redirects

The -L option tells curl to follow any redirect until it reaches the final destination:

$ curl -L google.com

Limit maximum transfer rate

Use limit-rate option with the curl command to limits the transfer rate of data transfer:

$ curl --limit-rate [value] [URL]
$ curl --limit-rate 500K -O http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso

Download Multiple files With curl command

If you want to download multiple files in single command then use multiple -O options similar as below:

$ curl -O [URL1] -O [URL2]
curl -O http://releases.ubuntu.com/18.04.2/ubuntu-18.04.2-desktop-amd64.iso  \
     -O http://releases.ubuntu.com/18.04.2/ubuntu-18.04.2-live-server-amd64.iso

Use Proxy to Access the URL

Curl command also allow you to use a proxy to access the URL. To transfer data via a proxy server, you can use the -x (--proxy) option with the curl command:

curl -x [proxy_name]:[port] [URL...]
curl -x 198.164.40.1:6600 http://example.com/

Use the -U (--proxy-user) option, if the proxy server requires authentication:

curl -u [user]:[password] -x [proxy_name]:[port] [URL...]
curl -U your_username:your_password -x 198.164.40.1:6600 http://example.com/

That’s all.

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top