Examples of Curl Command
-C – Option:
This option resumes download which has been stopped due to some reason. This is useful when downloading large files and was interrupted.
Syntax:
curl -C - [URL...]
Example:
curl -C - -O ftp://speedtest.tele2.net/1MB.zip
Output:
–limit-rate Option:
This option limits the upper bound of the rate of data transfer and keeps it around the given value in bytes.
Syntax:
curl --limit-rate [value] [URL]
Example:
curl --limit-rate 1000K -O ftp://speedtest.tele2.net/1MB.zip
Output:
The command limits the download to 1000K bytes.
-u Option:
curl also provides options to download files from user authenticated FTP servers.
Syntax:
curl -u {username}:{password} [FTP_URL]
Example:
curl -u demo:password -O ftp://test.rebex.net/readme.txt
Output:
-T Option:
This option helps to upload a file to the FTP server.
Syntax:
curl -u {username}:{password} -T {filename} {FTP_Location}
If you want to append an already existing FTP file you can use the -a or –append option.
–libcurl Option:
This option is very useful from a developer’s perspective. If this option is appended to any cURL command, it outputs the C source code that uses libcurl for the specified option. It is a code similar to the command line implementation.
Syntax:
curl [URL...] --libcurl [filename]
Example:
curl https://www.w3wiki.org > log.html --libcurl code.c
Output:
The above example downloads the HTML and saves it into log.html and the code in code.c file. The next command shows the first 30 lines of the code.
Sending mail:
As curl can transfer data over different protocols, including SMTP, we can use curl to send mails.
Syntax:
curl –url [SMTP URL] –mail-from [sender_mail] –mail-rcpt [receiver_mail] -n –ssl-reqd -u {email}:{password} -T [Mail text file]
DICT protocol:
The Libcurl defines the DICT protocol which can be used to easily get the definition or meaning of any word directly from the command line.
Syntax:
curl [protocol:[dictionary_URL]:[word]
Example:
curl dict://dict.org/d:overclock
Output:
Note: There are a number of other options provided by cURL which can be checked on the main page. The libcurl library has been ported into various programming languages. It’s advisable to visit the individual project site for documentation.
curl Command in Linux with Examples
In the realm of Linux, mastering the command line is essential for efficient and powerful usage of the operating system. Among the number of command line tools available, `curl`
stands out as one of the most versatile and powerful utilities. Originally developed by Daniel Stenberg, `curl`
is a command-line tool and library for transferring data with URLs. It supports a wide range of protocols, making it an invaluable tool for fetching, uploading, and managing data over the Internet. In this comprehensive guide, we delve into the intricacies of the `curl`
command in Linux, exploring its features, options, and various use cases.