Curl is the most essential command-line tool in Linux / UNIX for transfer data to or from a server using various protocols.
Most common supported protocols to curl utility are HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, Telnet, LDAP, etc.
Curl has capabilities to transfer multiple files at once.
We can do many more thing using curl utility using various options.
Suggested Reading: Linux curl command help and examples
Examples of curl command:
Example 1: curl use to download a file
You can use to download files from internet protocol http, https, FTP, etc.
To download a file from the internet, you can use curl with an option “-o,” and it will download and save the file into your current working directory with the same name an in the remote server.
Example 2: curl use to download multiple file
You can also download multiple files using CURL using the same option “-o” with all files, as shown below:
Example 3: curl use to download multiple files from list
Sometimes you have a list of files to download from internet or remote servers; In this case, you can make a text file with the list of downloaded files and use the “xargs” with curl to download all files with a single command, as shown below:
Example 4: Resume download uncompleted file
The CURL support resume to download interrupted files. To use these functionalities, use the “-c” option with curl, as shown below:
Example 5: CURL use proxy
Sometimes you use the proxy to surf the internet, especially in office in that case also you can use the curl command to download the file. You can use CURL like below example to use the proxy network.
Example 6: HTTP Headers query
Use HTTP header query to get the additional information from the remote server along with the actual request.
To request HTTP headers using curl command, follow below command:
Example 7: CURL use to POST request with parameters
You can use the curl command to post request with URL and parameters.
For example, in below command, we pass firstname and lastname parameters with their values, to https://linuxconcept.com/info.php
Example 8: CURL use to download files from FTP server
You can also use the curl command to download a file from FTP server.
Here we download a file “curltips.tar.gz” from ftp://linuxconcept.com using curl command as shown below:
You can remove “-u username:password” from above command if your FTP server allows anonymous login, if not you should replace username and password with your credentials.
Example 9: CURL use to upload files to an FTP server
The curl command also use to upload a file on FTP server.
Here we use curl command to upload a file “myform.tar.gz” to ftp://linuxconcept.com, as shown below:
Example 10: CURL can specify User agent
The user agent is sent information along with the HTTP request. It is use to identify the user’s platform and client application which is used to request any server. Generally, this information represents a web browser as the web browser generates maximum http requests.
By using curl command, you can specify user agent who will send through https request, as shown below:
Example 11: CURL use to store website cookies
The curl command also helps you to view and store website cookies into a file.
For example, if you want to see the cookies of https://www.cnn.com which is get downloaded into your browser when you browse the site. You can use below command to store cookies information into file “cnncookies.txt” which you can view using the cat command.
Example 12: CURL use to send website cookies
You can use the store cookies retrieved in the last example in a subsequent request to the same site.
Example 13: Modify name resolution
Curl command helps us to test development or staging sites using name resolution before moving it on a production server.
For example, the local version of “linuxconcept.com” before publishing it live, you can make curl resolve https://www.linuxconcept.com to your localhost system, as shown below:
The above query to https://www.linuxconcept.com will tell curl to request the site from localhost instead of using DNS or /etc/hosts file.
Example 14: Limit download rate in CURL command
To use your network bandwidth with optimal utilization, you can limit the download rate while using curl command.
You can limit the download bandwidth with curl command, as shown below:
Example 15: Check the version of CURL
To check the version of curl utility in Linux use it with the option “-v” or “–version,” as shown below: