Updated April 19, 2023
Introduction of Linux Curl Command
In the Linux ecosystem, the curl is nothing but a command-line utility or tool. It is useful to download the internet content on a Linux machine or server. It is majorly useful to transfer the data from one server to another server. It will support multiple protocols like FTP, FTPS, GOPHER, HTTP, HTTPS, etc. Without manual intervention, we are able to work on the curl utility. Hence the curl utility is generally ideal for automation jobs. All the curl transfer-related features are powered by libcurl.
The main author of the Linux curl command is Daniel Stenberg.
Syntax of Curl command
curl [options] [URL...]
- curl: We can use the curl keyword in the syntax or command. It will take the two arguments as an option and the URL. As per the provided arguments, it will provide the internet content, cookiesinformation, transfer the data, etc. (as per the user requirement).
- OPTION: We can provide the different flags as options that arecompatible with the curl command.
- URL: We need to provide the URL or website location to the curl command.
How Does Linux Curl Command Work?
The curl command or tool will accept the different compatibles option as well as the URL. As per the user requirement, curl command will do different operations like downloading the data from different websites, transfer the data, proxy use, authentication access, etc.
As discussed earlier, we are able to transfer the data from one server to another. While transferring the data, the curl command will support the below list of protocols;
Protocols:DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP,IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, TELNET and TFTP.
Below are the lists of options available in the curl command.
|1||-a, –append||It will tell curl command to append to the target file instead of overwriting it. If the file will not present then create the new file.|
|2||-A, –user-agent <agent string>||It is helpful to send the user agent string to the web or HTTP server.|
|3||–anyauth||It will identify the HTTP authentication mechanism by its own. But we are uploading the stdin data then the –anyauth is not recommended.|
|4||-b, –cookie||It will send the cookie data to the HTTP server|
|5||-B, –use-ascii||It will help to transfer the ASCII data/information|
|6||–basic||This option helps to curl command to use the basic HTTP authentication mechanism|
|7||–crlf||It will help to convert the LF to CRLF while updating the data (FTP).|
|8||–digest||It will enable the HTTP digest authentication|
|9||–engine <name>||To use for cheaper operations, it will help to select the OpenSSL crypto engine|
Examples to Implement Linux Curl Command
Following are the examples are given below:
It is a very simple and common curl command in a Linux environment. It will just download the file from the internet.
curl -O http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso
Explanation: We are able to download the CentOS 7 ISO file with the help of curl command.
2. Curl Command – With “-o” Option
In the curl command, we are having the functionality to download any file with our own file name. We need to use the “-o” option with the curl command.
curl -o Linux_CT_OS.iso http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso
Explanation: As per the above command, we are able to change the download file name as per our requirement. We have changed the file name to “Linux_CT_OS.iso”.
3. Curl Command – With “-C” Option
In the curl command, we are able to resume the download from the last point of disconnection. The download will not start from the start.
curl -C - -o Linux_CT_OS.iso http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso
Explanation: As per the above command, we are able to resume the old download file i.e. “Linux_CT_OS.iso”.
4. CurlCommand – To download multiple files
In the curl command, we are able to download multiple files at the same time. There is no need to execute the individual curl command to download multiple files.
curl -O http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.torrent -O http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso
Explanation: As per the above command, we are downloading the two files at the same time.
5. CurlCommand–Download from Input File
In the curl command, we are having the functionality to the files/data from the input file.
xargs -n 1 curl -O < download.txt
Explanation: We have created the “download.txt”. In the same file, we have kept the download URLs (we can keep multiple URLs as well). In the same file, we have provided the curl command as input. The curl command will download all the data as per the input.
6. Curl command – With “-I” Option
In the curl command, we are able to get the extra information of the HTTP server with the original request.
curl -I www.google.com
Explanation: As per the above command, we are getting extra information about the google web server.
7. Curl Command – Limit the Download Speed
In the curl command, we are having the functionality to limit on the download speed.
curl --limit-rate 50K -O http://centos.mirror.snu.edu.in/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-DVD-2003.iso
Explanation: As per the above command, we have set the download limit to 50KB. When the file will start the download, it will only consume the 50kb/s bandwidth.
8. Curl Command- Get Website Cookies
With the help of curl command, we are able to get the cookie information of a specific website.
curl --cookie-jar aajtakcookies.txt https://www.yupptv.com/channels/aajtak/live -O
Explanation: As per the below screenshot, we are getting the cookie information of yupptv website. It cookie information is store in the “aajtakcookies.txt” file.
We have seen the uncut concept of “Linux curl command” with the proper example, explanation, and command with different outputs. The curl command is very useful to move the data as well as to download the files from different websites. We can use the authentication mechanism while communicating.
We hope that this EDUCBA information on “Linux Curl Command” was beneficial to you. You can view EDUCBA’s recommended articles for more information.