Curl Command Line Example


HTTP & SOCKS Rotating Residential

  • 32 million IPs for all purposes
  • Worldwide locations
  • 3 day moneyback guarantee


Curl Command in Linux with Examples

Curl Command in Linux with Examples

curl is a command-line utility for transferring data from or to a server designed to work without user interaction. With curl, you can download or upload data using one of the supported protocols including HTTP, HTTPS, SCP, SFTP, and FTP. curl provides a number of options allowing you to resume transfers, limit the bandwidth, proxy support, user authentication, and much this tutorial, we will show you how to use the curl tool through practical examples and detailed explanations of the most common curl stalling Curl The curl package is pre-installed on most Linux distributions check whether the Curl package is installed on your system, open up your console, type curl, and press enter. If you have curl installed, the system will print curl: try ‘curl –help’ or ‘curl –manual’ for more information. Otherwise, you will see something like curl command not curl is not installed you can easily install it using the package manager of your stall Curl on Ubuntu and Debian sudo apt updatesudo apt install curlInstall Curl on CentOS and Fedora sudo yum install curlHow to Use Curl The syntax for the curl command is as follows:In its simplest form, when invoked without any option, curl displays the specified resource to the standard example, to retrieve the homepage you would run:curl command will print the source code of the homepage in your terminal no protocol is specified, curl tries to guess the protocol you want to use, and it will default to the Output to a File To save the result of the curl command, use either the -o or -O option. Lowercase -o saves the file with a predefined filename, which in the example below is -o -O saves the file with its original filename:curl -O Multiple files To download multiple files at once, use multiple -O options, followed by the URL to the file you want to the following example we are downloading the Arch Linux and Debian iso files:curl -O \ -O a Download You can resume a download by using the -C – option. This is useful if your connection drops during the download of a large file, and instead of starting the download from scratch, you can continue the previous example, if you are downloading the Ubuntu 18. 04 iso file using the following command:curl -O suddenly your connection drops you can resume the download with:curl -C – -O headers are colon-separated key-value pairs containing information such as user agent, content type, and encoding. Headers are passed between the client and the server with the request or the the -I option to fetch only the HTTP headers of the specified resource:curl -I –2 if a Website Supports HTTP/2 To check whether a particular URL supports the new HTTP/2 protocol, fetch the HTTP Headers with -I along with the –2 option:curl -I –2 -s | grep HTTPThe -s option tells curl to run in a silent (quiet) and hide the progress meter and error the remote server supports HTTP/2, curl prints HTTP/2. 0 200:HTTP/2 200
Otherwise, the response is HTTP/1. 1 200:HTTP/1. 1 200 OK
If you have curl version 7. 47. 0 or newer, you do not need to use the –2 option because HTTP/2 is enabled by default for all HTTPS Redirects By default, curl doesn’t follow the HTTP Location you try to retrieve the non-www version of, you will notice that instead of getting the source of the page you’ll be redirected to the www version:curl -L option instructs curl to follow any redirect until it reaches the final destination:curl -L mChange the User-Agent Sometimes when downloading a file, the remote server may be set to block the Curl User-Agent or to return different contents depending on the visitor device and situations like this to emulate a different browser, use the -A example to emulates Firefox 60 you would use:curl -A “Mozilla/5. 0 (X11; Linux x86_64; rv:60. 0) Gecko/20100101 Firefox/60. 0” a Maximum Transfer Rate The –limit-rate option allows you to limit the data transfer rate. The value can be expressed in bytes, kilobytes with the k suffix, megabytes with the m suffix, and gigabytes with the g the following example curl will download the Go binary and limit the download speed to 1 mb:curl –limit-rate 1m -O option is useful to prevent curl consuming all the available ansfer Files via FTP To access a protected FTP server with curl, use the -u option and specify the username and password as shown below:curl -u FTP_USERNAME:FTP_PASSWORD logged in, the command lists all files and directories in the user’s home can download a single file from the FTP server using the following syntax:curl -u FTP_USERNAME:FTP_PASSWORD upload a file to the FTP server, use the -T followed by the name of the file you want to upload:curl -T -u FTP_USERNAME:FTP_PASSWORD Cookies Sometimes you may need to make an HTTP request with specific cookies to access a remote resource or to debug an default, when requesting a resource with curl, no cookies are sent or send cookies to the server, use the -b switch followed by a filename containing the cookies or a example, to download the Oracle Java JDK rpm file
you’ll need to pass a cookie named oraclelicense with value a:curl -L -b “oraclelicense=a” -O Proxies curl supports different types of proxies, including HTTP, HTTPS and SOCKS. To transfer data through a proxy server, use the -x (–proxy) option, followed by the proxy following command downloads the specified resource using a proxy on 192. 168. 44. 1 port 8888:curl -x 192. 1:8888 the proxy server requires authentication, use the -U (–proxy-user) option followed by the user name and password separated by a colon (user:password):curl -U username:password -x 192. 1:8888 curl is a command-line tool that allows you to transfer data from or to a remote host. It is useful for troubleshooting issues, downloading files, and examples shown in this tutorial are simple, but demonstrate the most used curl options and are meant to help you understand how the curl command more information about curl visit the Curl Documentation
you have any questions or feedback, feel free to leave a comment.
Popular curl Examples - KeyCDN Support

HTTP & SOCKS Rotating & Static Proxies

  • 72 million IPs for all purposes
  • Worldwide locations
  • 3 day moneyback guarantee


Popular curl Examples – KeyCDN Support

Updated on October 4, 2018
What is curl? curl, short for “Client for URLs”, is a command line tool for transferring data using various protocols. This tool has applications in many household products such as tablets, printers, cars, routers, are a vast amount of use-cases for curl, such as:FTP uploadProxy supportSSL connectionsHTTP postThis tool also supports the use of all the following protocols: DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, and guide will outline a few popular curl examples, along with a description of what each command examplesThe following commands can all be entered directly into your terminal to retrieve a response. 1. HTTP GET requestThe first example is the most basic example which demonstrates a simple curl command that simulates a GET request for a website URL. This command will output the HTTP response of the URL in 2. Returning only the HTTP headers of a URLThe -I option is used to tell curl to only fetch the HTTP headers (HEAD method) of a particular page or -I 3. Saving the result of a curl commandThe -o and -O curl options are used to save the result of the curl command. The difference between both options is that -o will save the file with a predefined filename, which in this case is On the other hand, the -O option will save the file as its exisiting name, which is An example of each scenario is shown -o curl -O 4. Adding an additional HTTP request headerThis curl command has the ability to add an additional HTTP request header to your requests. Simply use the -H option and set the header name and value in enclosed quotes. If you do not define a value for the header then the header itself must be followed by a semicolon (e. g. X-Header;) -H “X-Header: value” 5. Generating additional informationThe -v option (for verbose) can be defined within a curl command so that it will generate more information during the operation. For example, using the additional header example from above, we can add the -v option which will display more information in regards to the connection and will display the custom header as well as regular -H “X-Header: value” -v
6. Resuming a downloadIf a download is started for a particular asset but gets interrupted or purposely stopped, it can easily be resumed with the -C option. Simply add -C – to the curl command in question and the asset will resume downloading where it left -C – -O 7. Storing HTTP headersWith the -D option, you have the ability to store the HTTP headers that a site sends back. This is useful for instance if you want to read the cookies from the headers by using a second curl command and including the -b option. The – after the -D tells curl that the output file is stdout (the file into which kernel writes its output) -D – 8. Testing the download time of an asset without any outputThe following command uses a couple of curl options to achieve the desired result. The -D – tells curl to store and display the headers in stdout and the -o option tells curl to download the defined resource. However, if you do not want any output, simply add /dev/null to the end of the command. This example can be useful if you are testing the download speed of an asset but don’t want to print or save the -D – -o /dev/null
9. Specifying a maximum transfer rateYou can specify the maximum transfer rate for both uploads and downloads with the –limit-rate option. The rate is measured in bytes/second unless a suffix, such K for kilobytes, M for megabytes, and G gigabytes, is added to the end of the specified –limit-rate 200K -O 10. HTTP/2 support checkIf you have the latest curl release, you can use the –2 option to check if a particular URL supports the new HTTP/2 protocol. Therefore, if the site does support HTTP/2, you will see HTTP/2. 0 200 in the header instead of HTTP/1. 1 -I –2 11. Retrieving a particular byte-rangeUse the -r option to retrieve a particular byte-range of a document. This essentially means to retrieve a particular portion of a file. These byte-range commands can be specified in a number of ways (e. 0-499 or 500-999). Read our article to learn more about Byte-Range -r 0-20000 -o 12. curl usage helpRun the -h option to quickly retrieve a list of helpful command line options with associated -h
curl examples to simulate HTTP methodscurl can also be useful for testing HTTP methods. The following is a list of request methods that can be used by running a curl command. 13. GET methodThe GET method is used to retrieve resources from a particular URL. The simple curl command will use GET as the default HTTP method, however it can also be specified using –request GET or -X –request GET 14. POST methodThe POST method is used to post information to a web server (e. a comment on a forum). This can be specified using –request POST or -X –request POST 15. DELETE methodThe DELETE method deletes the resource from the web server associated with a specific URL. This can be specified using –request DELETE or -X –request DELETE 16. PUT methodThe PUT method creates or replaces a resource based on the data the client submits to the web server. (e. g creating a new web page or updating an existing one). This can be specified using –request PUT or -X –request PUT 17. Making curl requests with dataYou can make requests using certain HTTP methods and also send along data via the -d or –data option. The example below uses a POST request which sends login data to a login page of a particular -X POST -d ‘username=yourusername&password=yourpassword’
SummaryThe above curl examples are amongst some of the most used and most popular. curl is a very useful tool for a variety of purposes including debugging, development, etc. Use this curl reference guide to help define specific curl examples of your own and visit the curl man page for a full list of curl options.
curl command in Linux with Examples - GeeksforGeeks

curl command in Linux with Examples – GeeksforGeeks

curl is a command line tool to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP or FILE). curl is powered by Libcurl. This tool is preferred for automation, since it is designed to work without user interaction. curl can transfer multiple file at [options] [URL… ]URL: The most basic uses of curl is typing the command followed by the This should display the content of the URL on the terminal. The URL syntax is protocol dependent and multiple URLs can be written as sets like:curl one, two, three}
URLs with numeric sequence series can be written as:curl 1-20]
Progress Meter: curl displays a progress meter during use to indicate the transfer rate, amount of data transferred, time left -# -o curl –silent If you like a progress bar instead of meter, you can use the -# option as in the example above, or –silent if you want to disable it completely. Example:Options:-o: saves the downloaded file on the local machine with the name provided in the -o [file_name] [URL… ]
Example:curl -o Output:The above example downloads the file from FTP server and saves it with the name: This option downloads the file and saves it with the same name as in the -O [URL… ]
Example:curl -O –: This option resumes download which has been stopped due to some reason. This is useful when downloading large files and was -C – [URL… ]
Example:curl -C – -O limit-rate: This option limits the upper bound of the rate of data transfer and keeps it around the given value in –limit-rate [value] [URL]
Example:curl –limit-rate 1000K -O Output:The command limits the download to 1000K bytes. -u: curl also provides options to download files from user authenticated FTP -u {username}:{password} [FTP_URL]
Example:curl -u demo:password -O: This option helps to upload a file to the FTP -u {username}:{password} -T {filename} {FTP_Location}
If you want to append a already existing FTP file you can use the -a or –append option. –libcurl:This option is very useful from a developers 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 the code similar to the command line [URL… ] –libcurl [filename]
Example:curl > –libcurl code. c
Output:The above example downloads the HTML and saves it into and the code in code. c file. The next command shows the first 30 lines of the code. -x, –proxy: curl also lets us use a proxy to access the -x [proxy_name]:[port] [URL… ]
If the proxy requires authentication, it can be used with the command:curl -u [user]:[password] -x [proxy_name]:[port] [URL… ]
Sending mail: As curl can transfer data over different protocols, including SMTP, we can use curl to send –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 [protocol:[dictionary_URL]:[word]
Example:curl dict
Output:Note: There are a number of other options provided by cURL which can be checked on the man page. The Libcurl library has been ported into various programming languages. It’s advisable to visit the individual project site for documentation.

Frequently Asked Questions about curl command line example

What is curl command line?

cURL, which stands for client URL, is a command line tool that developers use to transfer data to and from a server. At the most fundamental, cURL lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send.Feb 23, 2021

How do you write a curl command?

The syntax for the curl command is as follows: curl [options] [URL…] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the homepage in your terminal window.Nov 27, 2019

How do I run a curl command in Terminal?

Install curl on Windows Most likely, you’ll want to choose the With Administrator Privileges (free) installer. After you install curl, test your version of curl by doing the following: Open a command prompt by clicking the Start button and typing cmd. Type curl -V .Jan 1, 2019

About the author


If you 're a SEO / IM geek like us then you'll love our updates and our website. Follow us for the latest news in the world of web automation tools & proxy servers!

By proxyreview

Recent Posts

Useful Tools