Learn the many ways you can use the Curl command in Linux
Uses of the Linux Curl Command, The curl command can be used to transfer files over a network or from the internet the use of some of distinct formats which includes http, https, ftp or even smb.
The curl command has masses of various authentication techniques. You can use it to get admission to FTP web sites, send emails, hook up with SAMBA addresses, upload and down load documents and many other things.
Note:The curl command has a whole lot of parameters to learn. You can see a complete listing of them at the curl manual web page.
The Linux Curl Command,Basic curl Command Usage
Uses of the Linux Curl Command, The curl command can be used to download documents from the net, however in its primary form, you may download the internet page content material straight to the terminal window.
For instance, input the subsequent command right into a terminal window:
curl http://linux.lifewire.com/cs/linux101/g/curl.htm
The output will scroll up in the terminal window and it’s going to display you the code for the related web site.
Obviously, the web page scrolls too speedy to read and so if you wish to slow it down you should use either the much less command or the greater command.
curl http://linux.lifewire.com/cs/linux101/g/curl.htm | more
The Linux Curl Command,Output the Contents of curl to a File
Uses of the Linux Curl Command, The trouble with the primary curl command usage is that the text scrolls very rapid. If you’re downloading a report such as an ISO image, you don’t want this going to the standard output.
To keep the content to a document, all you need to do is specify the minus o (-o) switch as follows:
curl -o <filenametocreate> <URL>
To down load the page related to inside the fundamental command usage phase, all you need to do is input the following command:
curl -o curl.htm http://linux.lifewire.com/cs/linux101/g/curl.htm
After the file has downloaded, you may open it in an editor or its default application determined by the report type.
You can simplify this further through using the minus O switch (-O) as follows:
curl -O http://linux.lifewire.com/cs/linux101/g/curl.htm
This will use the filename portion of the URL and make it the filename that the URL is stored to. In the above example, the record will be known as curl.Htm.
The Linux Curl Command,Run the Curl Command In the Background
By default, the curl command indicates a progress bar telling you how plenty of the switch is left and how much information has been transferred.
If you simply need the command to run without a progress bar, you may want to run it in silent mode. Then run it as a heritage command.
To run a command silently use the subsequent command:
curl -s -O <URL>
To get the command to run in the history, you want to apply the ampersand (&) as follows:
curl -s -O <URL> &
Note:Running the culr command without the progress bar is extra streamlined, but you might not know how long the switch will take or the estimated time it have to entire.
The Linux Curl Command,Downloading Multiple URLs with Curl
You can down load from more than one URLs using a single curl command.
In its only shape, you could download a couple of URLs as follows:
curl -O http://www.mysite.com/page1.html -O http://www.mysite.com/page2.html
Imagine you have a folder with a hundred pics all referred to as image1.Jpg, image2.Jpg, image3.Jpg, etc. You would not need to ought to type in all of these URLs.
To do that, you could use square brackets to deliver a variety. For example, to get documents 1 to a hundred, you may specify the subsequent:
curl -O http://www.mysite.com/images/image[1-100].jpg
You also can use curly brackets to specify a couple of web sites with similar codecs.
For instance, believe you need to download www.Google.Com and www.Bing.Com. You can certainly use the following command to accomplish this:
curl -O http://www.{google,bing}.com
The Linux Curl Command,Displaying Progress
By default the curl command returns the following information as it downloads a URL:
- Total %: Percent of overall switch completed.
- Total bytes: Total length of the transfer in bytes.
- Received/Transferred %: Percentage of transfer finished.
- Received/Transferred bytes: Number of bytes downloaded.
- Average download pace: Download pace in bytes consistent with second.
- Average add pace: Upload velocity in bytes in line with 2nd.
- Total time: Estimated time to complete the modern-day operation.
- Time spent: Time handed for the reason that start of switch.
- Time left: Expected time to complete the switch.
- Current speed: Current transfer pace in bytes in keeping with second.
If you will decide on a simple progress bar, just specify the minus hash (-#) switch as follows:
curl -# -O <URL>
The Linux Curl Command,Handling Redirects
Imagine you have got detailed a URL as part of the curl command and assume you’ve got the right deal with to down load a huge file handiest to return again later to find that each one you have is a web site pointing out “this page has been redirected to www.Blah.Com”. That would be worrying, would not it?
The curl command is clever in that it may follow redirects. All you need to do is use the minus L switch (-L) as follows:
curl -OL <URL>
The Linux Curl Command,Reduce the Download Rate
If you’re downloading a massive record and you have a bad internet connection then you definitely may annoy the own family if they’re looking to do stuff on the net as nicely.
Fortunately, you can reduce the down load price with the curl command.
curl -O --limit-rate 1m <URL>
The rate can be laid out in kilobytes (k or K), megabytes (m or m) or gigabytes (g or G).
Note: Keep in mind that decreasing the download speed will boom the time it takes for a transfer to finish.
The Linux Curl Command ,Download Files From an FTP Server
The curl command can handle extra than just HTTP document transfers. It can cope with FTP, GOPHER, SMB, HTTPS and many different codecs.
To download documents from an FTP server use the subsequent command:
curl -u user:password -o <URL>
If you specify the name of a file as a part of the URL then it’s going to download the file however in case you specify the name of a folder it’s going to return a folder listing.
You also can use curl to upload documents to an FTP server with the aid of the usage of the subsequent command:
curl -u user:password -T <filename(s)> <URL>
The filenames and can use the equal pattern matching as for downloading a couple of HTTP files.
The Linux Curl Command, Passing Form Data to a Form
You can use curl to fill in an internet shape and publish the facts as in case you had crammed it in your self. Many famous services together with Google block this type of usage.
Imagine there is a shape with a name and e mail cope with. You can put up this facts as follows:
curl -d name=john [email protected] www.mysite.com/formpage.php