{"id":12458,"date":"2019-03-27T01:47:58","date_gmt":"2019-03-27T01:47:58","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12458"},"modified":"2019-03-27T01:48:34","modified_gmt":"2019-03-27T01:48:34","slug":"15-tips-on-how-to-use-curl-command-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/15-tips-on-how-to-use-curl-command-in-linux\/","title":{"rendered":"15 Tips On How to Use \u2018Curl\u2019 Command in Linux"},"content":{"rendered":"<p>Back in the mid-1990\u2019s when the Internet was still in its infancy, a Swedish programmer named\u00a0<strong>Daniel Stenberg<\/strong>started a project that eventually grew into what we know as\u00a0<strong>curl<\/strong>\u00a0today.<\/p>\n<p>Initially, he aimed at developing a\u00a0<strong>bot<\/strong>\u00a0that would download currency exchange rates from a web page periodically and would provide Swedish Kronor equivalents in US dollars to IRC users.<\/p>\n<p>Long story short, the project thrived, adding several protocols and features along the way \u2013 and the rest is history. Now let\u2019s dive in with both feet and learn how to use curl to transfer data and more in Linux!<\/p>\n<p>We have put together the following list of 15 curl commands for you.<\/p>\n<h3>1. View curl Version<\/h3>\n<p>The\u00a0<code>-V<\/code>\u00a0or\u00a0<code>--version<\/code>\u00a0options will not only return the version, but also the supported protocols and features in your current version.<\/p>\n<pre><strong>$ curl --version<\/strong>\r\n\r\ncurl 7.47.0 (x86_64-pc-linux-gnu) libcurl\/7.47.0 GnuTLS\/3.4.10 zlib\/1.2.8 libidn\/1.32 librtmp\/2.3\r\nProtocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp \r\nFeatures: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets \r\n<\/pre>\n<h3>2. Download a File<\/h3>\n<p>If you want to download a file, you can use\u00a0<strong>curl<\/strong>\u00a0with the\u00a0<code>-O<\/code>\u00a0or\u00a0<code>-o<\/code>\u00a0options. The former will save the file in the current working directory with the same name as in the remote location, whereas the latter allows you to specify a different filename and\/or location.<\/p>\n<pre>$ curl -O http:\/\/yourdomain.com\/yourfile.tar.gz # Save as yourfile.tar.gz\r\n$ curl -o newfile.tar.gz http:\/\/yourdomain.com\/yourfile.tar.gz # Save as newfile.tar.gz\r\n<\/pre>\n<h3>3. Resume an Interrupted Download<\/h3>\n<p>If a download was interrupted for some reason (for example, using\u00a0<code>Ctrl + c<\/code>), you can resume it very easily. The use of\u00a0<code>-C<\/code>\u00a0\u2013 (dash C, space dash) tells curl to resume the download beginning where it left off.<\/p>\n<pre>$ curl -C - -O http:\/\/yourdomain.com\/yourfile.tar.gz\r\n<\/pre>\n<div id=\"attachment_30279\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-File-Using-Curl-Command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30279\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-File-Using-Curl-Command.png\" sizes=\"auto, (max-width: 1246px) 100vw, 1246px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-File-Using-Curl-Command.png 1246w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-File-Using-Curl-Command-768x194.png 768w\" alt=\"Download File Using Curl Command\" width=\"1246\" height=\"314\" aria-describedby=\"caption-attachment-30279\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30279\" class=\"wp-caption-text\">Download File Using Curl Command<\/p>\n<\/div>\n<h3>4. Download Multiple Files<\/h3>\n<p>With the following command you will download\u00a0<strong>info.html<\/strong>\u00a0and\u00a0<strong>about.html<\/strong>\u00a0from\u00a0<strong>http:\/\/yoursite.com<\/strong>\u00a0and\u00a0<strong>http:\/\/mysite.com<\/strong>, respectively, in one go.<\/p>\n<pre>$ curl -O http:\/\/yoursite.com\/info.html -O http:\/\/mysite.com\/about.html \r\n<\/pre>\n<h3>5. Download URLs From a File<\/h3>\n<p>If you combine\u00a0<strong>curl<\/strong>\u00a0with\u00a0<a href=\"https:\/\/www.tecmint.com\/xargs-command-examples\/\" target=\"_blank\" rel=\"noopener\">xargs<\/a>, you can download files from a list of URLs in a file.<\/p>\n<pre>$ xargs -n 1 curl -O &lt; listurls.txt\r\n<\/pre>\n<div id=\"attachment_30280\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-Multiple-Files-with-Curl.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30280\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-Multiple-Files-with-Curl.png\" sizes=\"auto, (max-width: 1027px) 100vw, 1027px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-Multiple-Files-with-Curl.png 1027w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Download-Multiple-Files-with-Curl-768x394.png 768w\" alt=\"Download Multiple Files with Curl\" width=\"1027\" height=\"527\" aria-describedby=\"caption-attachment-30280\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30280\" class=\"wp-caption-text\">Download Multiple Files with Curl<\/p>\n<\/div>\n<h3>6. Use a Proxy with or without Authentication<\/h3>\n<p>If you are behind a proxy server listening on port\u00a0<strong>8080<\/strong>\u00a0at\u00a0<strong>proxy.yourdomain.com<\/strong>, do.<\/p>\n<pre>$ curl -x proxy.yourdomain.com:8080 -U user:password -O http:\/\/yourdomain.com\/yourfile.tar.gz\r\n<\/pre>\n<p>where you can skip\u00a0<strong>-U user:password<\/strong>\u00a0if your proxy does not require authentication.<\/p>\n<h3>7. Query HTTP Headers<\/h3>\n<p><strong>HTTP<\/strong>\u00a0headers allow the remote web server to send additional information about itself along with the actual request. This provides the client with details on how the request is being handled.<\/p>\n<p>To query the HTTP headers from a website, do:<\/p>\n<pre>$ curl -I www.tecmint.com\r\n<\/pre>\n<div id=\"attachment_30281\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Query-HTTP-Headers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30281\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Query-HTTP-Headers.png\" alt=\"Curl Query HTTP Headers\" width=\"585\" height=\"427\" aria-describedby=\"caption-attachment-30281\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30281\" class=\"wp-caption-text\">Curl Query HTTP Headers<\/p>\n<\/div>\n<p>This information is also available in your browser\u2019s developer tools.<\/p>\n<h3>8. Make a POST request with Parameters<\/h3>\n<p>The following command will send the\u00a0<strong>firstName<\/strong>\u00a0and\u00a0<strong>lastName<\/strong>\u00a0parameters, along with their corresponding values, to\u00a0<strong>https:\/\/yourdomain.com\/info.php<\/strong>.<\/p>\n<pre>$ curl --data \"firstName=John&amp;lastName=Doe\" https:\/\/yourdomain.com\/info.php\r\n<\/pre>\n<p>You can use this tip to simulate the behavior of a regular HTML form.<\/p>\n<h3>9. Download Files from an FTP Server with or without Authentication<\/h3>\n<p>If a remote FTP server is expecting connections at\u00a0<strong>ftp:\/\/yourftpserver<\/strong>, the following command will download\u00a0<strong>yourfile.tar.gz<\/strong>\u00a0in the current working directory.<\/p>\n<pre>$ curl -u username:password -O ftp:\/\/yourftpserver\/yourfile.tar.gz \r\n<\/pre>\n<p>where you can skip\u00a0<strong>-u username:password<\/strong>\u00a0if the\u00a0<a href=\"https:\/\/www.tecmint.com\/setup-ftp-anonymous-logins-in-linux\/\" target=\"_blank\" rel=\"noopener\">FTP server allows anonymous logins<\/a>.<\/p>\n<h3>10. Upload Files to an FTP server with or without Authentication<\/h3>\n<p>To upload a local file named\u00a0<strong>mylocalfile.tar.gz<\/strong>\u00a0to\u00a0<strong>ftp:\/\/yourftpserver<\/strong>\u00a0using curl, do:<\/p>\n<pre>$ curl -u username:password -T mylocalfile.tar.gz ftp:\/\/yourftpserver\r\n<\/pre>\n<h3>11. Specify User Agent<\/h3>\n<p>The\u00a0<strong>user agent<\/strong>\u00a0is part of the information that is sent along with an\u00a0<strong>HTTP<\/strong>\u00a0request. This indicates which browser the client used to make the request. Let\u2019s see what our current curl version uses as default, and let\u2019s change it later to \u201c<strong>I am a new web browser<\/strong>\u201d:<\/p>\n<pre>$ curl -I http:\/\/localhost --user-agent \"I am a new web browser\"\r\n<\/pre>\n<div id=\"attachment_30282\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Check-User-Agent.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30282\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Check-User-Agent.png\" sizes=\"auto, (max-width: 1158px) 100vw, 1158px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Check-User-Agent.png 1158w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Check-User-Agent-768x333.png 768w\" alt=\"Curl Check User Agent\" width=\"1158\" height=\"502\" aria-describedby=\"caption-attachment-30282\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30282\" class=\"wp-caption-text\">Curl Check User Agent<\/p>\n<\/div>\n<h3>12. Store Website Cookies<\/h3>\n<p>Want to see which cookies are downloaded to your computer when you browse to\u00a0<strong>https:\/\/www.cnn.com<\/strong>? Use the following command to save them to\u00a0<strong>cnncookies.txt<\/strong>. You can then use\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>\u00a0to view the file.<\/p>\n<pre>$ curl --cookie-jar cnncookies.txt https:\/\/www.cnn.com\/index.html -O\r\n<\/pre>\n<div id=\"attachment_30283\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Store-Cookies.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30283\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Store-Cookies.png\" sizes=\"auto, (max-width: 1128px) 100vw, 1128px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Store-Cookies.png 1128w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/08\/Curl-Store-Cookies-768x301.png 768w\" alt=\"Curl Store Website Cookies\" width=\"1128\" height=\"442\" aria-describedby=\"caption-attachment-30283\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30283\" class=\"wp-caption-text\">Curl Store Website Cookies<\/p>\n<\/div>\n<h3>13. Send Website Cookies<\/h3>\n<p>You can use the cookies retrieved in the last tip in subsequent requests to the same site.<\/p>\n<pre>$ curl --cookie cnncookies.txt https:\/\/www.cnn.com\r\n<\/pre>\n<h3>14. Modify Name Resolution<\/h3>\n<p>If you\u2019re a web developer and want to test a local version of\u00a0<strong>yourdomain.com<\/strong>\u00a0before pushing it live, you can make curl resolve\u00a0<strong>http:\/\/www.yourdomain.com<\/strong>\u00a0to your localhost like so:<\/p>\n<pre>$ curl --resolve www.yourdomain.com:80:localhost http:\/\/www.yourdomain.com\/<\/pre>\n<p>Thus, the query to\u00a0<strong>http:\/\/www.yourdomain.com<\/strong>\u00a0will tell curl to request the site from localhost instead of using DNS or the\u00a0<strong>\/etc\/hosts<\/strong>\u00a0file.<\/p>\n<h3>15. Limit Download Rate<\/h3>\n<p>To prevent curl from hosing your bandwidth, you can limit the download rate to\u00a0<strong>100 KB\/s<\/strong>\u00a0as follows.<\/p>\n<pre>$ curl --limit-rate 100K http:\/\/yourdomain.com\/yourfile.tar.gz -O\r\n<\/pre>\n<h5>Summary<\/h5>\n<p>In this article we have shared a brief history of the origins of curl and explained how to use it through 15 practical examples.<\/p>\n<p>Do you know of any other curl commands that we may have missed in this article? Feel free to share them with our community in the comments! Also, if you have questions feel free to let us know. We look forward to hearing from you!<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-curl-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the mid-1990\u2019s when the Internet was still in its infancy, a Swedish programmer named\u00a0Daniel Stenbergstarted a project that eventually grew into what we know as\u00a0curl\u00a0today. Initially, he aimed at developing a\u00a0bot\u00a0that would download currency exchange rates from a web page periodically and would provide Swedish Kronor equivalents in US dollars to IRC users. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/27\/15-tips-on-how-to-use-curl-command-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;15 Tips On How to Use \u2018Curl\u2019 Command in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12458","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12458"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12458\/revisions"}],"predecessor-version":[{"id":12460,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12458\/revisions\/12460"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}