10 Simple cURL Commands with Examples on Linux

cURL Commands in Linux

What is cURL?

cURL is an abbreviation for Client URL Request Library. Basically cURL is name of the project. ​cURL is used to transfer data from one place to another place. It is a command line tool for receiving and sending files using URL syntax. It consists of different cURL Commands and libraries which can work with different protocols.

​CURL and WGET have few similarities. WGET can be used to download single file/folder where as CURL can download multiple files in a single shot.

​WGET can download an entire website with a single command. WGET only offers plain http post support where as CURL offers uploading and sending capabilities.

Advantages with CURL

  • We can see the downloaded file directly on console
  • Ability to save downloads to a particular file name.
  • With a single command we can download multiple files.
  • There is an option to resume the download, from where it stops.
  • Can set the rate limits for your downloads.
  • it can work on all protocols.
  • Shows the stats for the download like percentage, time.
  • Works on wide variety of protocols and can be used on any of your programs.

Basic cURL Commands 

Let's see few basic cURL Commands

Downloading a web page using cURL?

For example you wish to see the content of a website, you can use below command

curl http://fastwebhost.in

Above command will only display the web page content , obviously, the page will be long so it keeps scrolling up.

To see the page slowly we can add less, more using | to the above command like​

curl fastwebhost.in | more & curl fastwebhost.in | less​

​Saving the output to a file

​Above cURL Commands will only display the content of the web page you requested, You can also save the output into a file directly, 

curl -o san.html fastwebhost.in/san.html​

Using -o to curl command and giving a specific file name will save output to that file, Above instance san.html is the filename and content can be viewed with an editor.

curl -O fastwebhost.in/san.html​

 Adding -O to CURL command it will use the tail part of the URL and downloads the content to that file. Above instance, file be saved as "san.html"

Downloading multiple files at a time

curl -O fastwebhost.in/1.html -O fastwebhost.in/2.html​

Above command will download both the URL's at a time and benefit of using -O is that file can be saved directly to the file name, whereas in above case it saves with 1.html and 2.html

Continuing Download

curl -C fastwebhost.in

This command would be very useful when you are trying t download a big file and when any downloading file gets interrupted.​ Adding -C will resume the download where it got stopped.

Data Transferring Limit

curl --limit-rate 100m -O fastwebhost.com/san.html

Use --limit-rate command to limit the data transfer to 100m. We can also give k, G. K = kilobytes G = Gigabytes

Showing Stats for the download

curl -# -O fastwebhost.com

Adding -# above command will show the progress bar like total %,data transfer limits,downloaded speed,upload speed,time spent,time remaining.

As discussed earlier curl will support various protocols.

Downloading and Uploading files to FTP using cURL Command

curl ftp://fastwebhost.com --user username:passowrd 

The above command will be listing files and directories under your root folder.

curl ftp://fastwebhost.com/san.tar.gz --user username:passowrd -o san.tar.gz

Above command it will download the san.tar.gz file.

curl -T san.tar.gz ftp://fastwebhost.com/directory --user username:passowrd

Adding -T above command can upload the files to mentioned specific directory by giving it as above.

curl ftp://fastwebhost.com -X 'DELE san.tar.gz' --user username:passowrd

Adding -X above command  can delete the mentioned file.

Ignoring SSL Certificate warnings

curl -k https://fastwebhost.com

Sometimes when we access any website on browser it requires some user action like accepting "Advance section" "continue", In that case we can use -k this will accept and continue.

Sending Emails using cURL Command

curl --mail-from san@fastwebhost.com --mail-rcpt shiv@fastwebhost.com smtp:// ip or mailserver.com

Once you type the above command it will ask you to write the message after entering the message we need to give .(period) at last line which will be sending the email.

Downloading a file after a specific modification time

curl -z 8-feb-17 http://fastwebhost.com/san.html

Adding -z to curl command it will download a file only if the modification has done after the mentioned time in above command.

Conclusion

cURL Command can be used in different methods and can be used for various protocols like accessing FTP sites, sending emails,etc. Also, we keep updating this post with new commands. Keep watching.

Click Here to Leave a Comment Below

Leave a Comment:

Get a Free Hosting Trial and Test Our Services. It Costs Nothing! Get it Here!  

x