Curl command is used to transfer files to and from a server, it supports a number of protocols like HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, DICT, FILE, GOPHER, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP etc.

Curl also supports a lot of features like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer pause & resume, etc. There are around 120 different options that can be used with curl & in this tutorial, we are going to discuss some important Curl commands with examples.

(Recommended Read: Useful Linux Commands that you should know)

(Also Read: Commands to check System & Hardware Information)

 

Curl command with examples

Download or visit a single URL

To download a file using CURL from http or ftp or any other protocol, use the following command

$ curl https://linuxtechlab.com

If curl can't identify the protocol being used, it will switch to http. We can also store the output of the command to a file with '-o' option or can also redirect using '>',

$ curl https://linuxtechlab.com -o test.html , or,

$ curl https://linuxtechlab.com > test.html

 

Download multiple files

To download two or more files with curl in a single command, we will use '-O' option. Complete command is,

$ curl -O https://linuxtechlab.com/test1.tar.gz -O https://linuxtechlab.com/test2.tar.gz

 

Using ftp with curl

To browse a ftp server, use the following command,

$ curl ftp://test.linuxtechlab.com --user username:password

To download a file from the ftp server, use the following command,

$ curl ftp://test.linuxtechlab.com/test.tar.gz --user username:password -o test.tar.gz

To upload a file to the ftp server using th curl command, use the following,

$ curl -T test.zip ftp:/test.linuxtechlab.com/test_directory/ --user username:password

 

Resume a paused download

We can also pause and resume a download with curl command. To do this, we will first start the download ,

$ curl -O https://linuxtechlab.com/test1.tar.gz

than pause the download using 'ctrl+C' & to resume the download, use the following command,

$ curl -C - -O https://linuxtechlab.com/test1.tar.gz

here, '-C' option is used to resume the download.

 

Sending an email

Though you might not be using it any time soon, but none the less we can use curl command to send email. Complete command for sending an email is,

$ curl --url "smtps://smtp.linuxtechlab.com:465" --ssl-reqd --mail-from "dan@linuxtechlab.com" --mail-rcpt "susan@readlinux.com" --upload-file mailcontent.txt --user "dan@linuxtechlab.com:password" --insecure

 

Limit download rate

To limit the rate at which a file is downloaded, in order to avoid network choking or for some other reason, use the curl command with '--limit-rate' option,

$ curl --limit-rate 200k -O https://linuxtechlab.com/test.tar.gz

 

Show response headers

To only see the response header of a URL & not the complete content , we can use option '-I' with curl command,

$ curl -I https://linuxtechlab.com/

This will only show the headers like http protocol, Cache-contorol headers, content-type etc of the mentioned url.

 

Using http authentication

We can also use curl to open a web url that has http authentication enabled with curl using '-u ' option. Complete command is,

$ curl -u user:passwd https://linuxtechlab.com

 

Using a proxy

To use a proxy server when visiting an URL or downloading, use '-x' option with curl,

$ curl -x squid.proxy.com:3128 https://linuxtechlab.com

 

Verifying Ssl certificate

To verify a SSL certificate of an URL, use the following command,

$ curl --cacert ltchlb.crt https://linuxtechlab.com

 

Ignoring SSL certificate

To ignore the SSL certificate for an URL, we can use '-k' option with curl command,

$ curl -k https://linuxtechlab.com

With this we end our tutorial on learning CURL command with examples. Please leave your valuable feedback & questions in the comment box below.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.