{"id":9307,"date":"2019-02-08T19:34:12","date_gmt":"2019-02-08T19:34:12","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=9307"},"modified":"2019-02-10T05:22:35","modified_gmt":"2019-02-10T05:22:35","slug":"learn-to-use-curl-command-with-examples-linux-com","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/02\/08\/learn-to-use-curl-command-with-examples-linux-com\/","title":{"rendered":"Learn to Use curl Command with Examples | Linux.com"},"content":{"rendered":"<p>Curl command is used to transfer files to and from a server, it supports a number of protocols like HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, DICT, FILE, GOPHER, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP etc.<\/p>\n<p>Curl also supports a lot of features like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer pause &amp; resume, etc. There are around 120 different options that can be used with curl &amp; in this tutorial, we are going to discuss some important Curl commands with examples.<\/p>\n<h2 class=\"fittexted_for_content_h2\"><b>Curl command with examples<\/b><\/h2>\n<p><strong>Download or visit a single URL<\/strong><\/p>\n<p>To download a file using CURL from http or ftp or any other protocol, use the following command<\/p>\n<p><strong>$ curl https:\/\/linuxtechlab.com<\/strong><\/p>\n<p>If curl can\u2019t identify the protocol being used, it will switch to http. We can also store the output of the command to a file with \u2018-o\u2019 option or can also redirect using \u2018&gt;\u2019,<\/p>\n<p><strong>$ curl https:\/\/linuxtechlab.com -o test.html<\/strong>\u00a0, or,<\/p>\n<p><strong>$ curl https:\/\/linuxtechlab.com &gt; test.html<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Download multiple files<\/strong><\/p>\n<p>To download two or more files with curl in a single command, we will use \u2018-O\u2019 option. Complete command is,<\/p>\n<p><strong>$ curl -O https:\/\/linuxtechlab.com\/test1.tar.gz -O https:\/\/linuxtechlab.com\/test2.tar.gz<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Using ftp with curl<\/strong><\/p>\n<p>To browse a ftp server, use the following command,<\/p>\n<p><strong>$ curl ftp:\/\/test.linuxtechlab.com \u2013user username:password<\/strong><\/p>\n<p>To download a file from the ftp server, use the following command,<\/p>\n<p><strong>$ curl ftp:\/\/test.linuxtechlab.com\/test.tar.gz \u2013user username:password -o test.tar.gz<\/strong><\/p>\n<p>To upload a file to the ftp server using th curl command, use the following,<\/p>\n<p><strong>$ curl -T test.zip ftp:\/test.linuxtechlab.com\/test_directory\/ \u2013user username:password<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Resume a paused\u00a0<\/strong><b>download<\/b><\/p>\n<p>We can also pause and resume a download with curl command. To do this, we will first start the download ,<\/p>\n<p><strong>$ curl -O https:\/\/linuxtechlab.com\/test1.tar.gz<\/strong><\/p>\n<p>than pause the download using\u00a0<strong>\u2018ctrl+C\u2019<\/strong>\u00a0&amp; to resume the download, use the following command,<\/p>\n<p><strong>$ curl -C \u2013 -O https:\/\/linuxtechlab.com\/test1.tar.gz<\/strong><\/p>\n<p>here, \u2018-C\u2019 option is used to resume the download.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Sending an email<\/strong><\/p>\n<p>Though you might not be using it any time soon, but none the less we can use curl command to send email. Complete command for sending an email is,<\/p>\n<p><strong>$ curl \u2013url \u201csmtps:\/\/smtp.linuxtechlab.com:465\u201d \u2013ssl-reqd \u2013mail-from \u201cdan@linuxtechlab.com\u201d \u2013mail-rcpt \u201csusan@readlinux.com\u201d \u2013upload-file mailcontent.txt \u2013user \u201cdan@linuxtechlab.com:password\u201d \u2013insecure<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Limit download rate<\/strong><\/p>\n<p>To limit the rate at which a file is downloaded, in order to avoid network choking or for some other reason, use the curl command with \u2018\u2013limit-rate\u2019 option,<\/p>\n<p><strong>$ curl \u2013limit-rate 200k -O https:\/\/linuxtechlab.com\/test.tar.gz<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Show response headers<\/strong><\/p>\n<p>To only see the response header of a URL &amp; not the complete content , we can use option \u2018-I\u2019 with curl command,<\/p>\n<p><strong>$ curl -I https:\/\/linuxtechlab.com\/<\/strong><\/p>\n<p>This will only show the headers like http protocol, Cache-contorol headers, content-type etc of the mentioned url.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Using http authentication<\/strong><\/p>\n<p>We can also use curl to open a web url that has http authentication enabled with curl using \u2018-u \u2018 option. Complete command is,<\/p>\n<p><strong>$ curl -u user:passwd https:\/\/linuxtechlab.com<\/strong><\/p>\n<p><strong>Using a proxy<\/strong><\/p>\n<p>To use a proxy server when visiting an URL or downloading, use \u2018-x\u2019 option with curl,<\/p>\n<p><strong>$ curl -x squid.proxy.com:3128 https:\/\/linuxtechlab.com<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Verifying Ssl certificate<\/strong><\/p>\n<p>To verify a SSL certificate of an URL, use the following command,<\/p>\n<p><strong>$ curl \u2013cacert ltchlb.crt https:\/\/linuxtechlab.com<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Ignoring SSL certificate<\/strong><\/p>\n<p>To ignore the SSL certificate for an URL, we can use \u2018-k\u2019 option with curl command,<\/p>\n<p><strong>$ curl -k https:\/\/linuxtechlab.com<\/strong><\/p>\n<p>With this we end our tutorial on learning CURL command with examples. Please leave your valuable feedback &amp; questions in the comment box below.<\/p>\n<p><a href=\"https:\/\/www.linux.com\/news\/learn-use-curl-command-examples-0\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Curl command is used to transfer files to and from a server, it supports a number of protocols like HTTP, HTTPS, FTP, FTPS, IMAP, IMAPS, DICT, FILE, GOPHER, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP etc. Curl also supports a lot of features like proxy support, user &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/02\/08\/learn-to-use-curl-command-with-examples-linux-com\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Learn to Use curl Command with Examples | Linux.com&#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-9307","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\/9307","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=9307"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/9307\/revisions"}],"predecessor-version":[{"id":9443,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/9307\/revisions\/9443"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=9307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=9307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=9307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}