Table of Contents
In this article, I will take you through 20 Useful curl command in Linux with Examples. curl is very powerful command line tool to send or receive GET and POST request/response from web server. You can even use this tool to upload your data in the FTP Server. There are other useful operations like checking the remote server port, download files etc can be performed using curl command in Linux. curl command supports different protocols like HTTP, HTTPS, TLS, FTP, SSL, SMTP, POP3, SCP, LDAP, IMAP etc. We will check the usage of curl command in various places using different examples.
Syntax
curl [options] [URL...]
20 Useful curl command in Linux with Examples
Also Read: 40 Best Examples of find command in Linux
Example 1: How to check curl command version
If you want to check the curl command version then you need to use curl --version
command as shown below. As you can see from below output, current curl command version is 7.29.0
.
[root@localhost ~]# curl --version curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.44 zlib/1.2.7 libidn/1.28 libssh2/1.8.0 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets
--version: Displays information about curl and the libcurl version it uses.
Example 2: How to Test a Remote Server Port Connection
If you want to test a Remote Server port connection then you need to use below curl command. In this example we are using telnet to test remote server google.com port 443
using curl -v telnet://google.com:443
as shown below.
[root@localhost ~]# curl -v telnet://google.com:443 * About to connect() to google.com port 443 (#0) * Trying 172.217.161.174... * Connected to google.com (172.217.161.174) port 443 (#0)
Example 3: How to retrieve home page of a URL
If you want to retrieve home page of a URL then you need to simply use below curl command. In this example, we are trying to download google.com page using curl https://www.google.com
command.
[root@localhost ~]# curl https://www.google.com <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-IN"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="/DtIAfvHmrcydJiSPzX1jw==">(function(){window.google={kEI:'uqDkXuzZJ83X-Qboyb-AAw',kEXPI:'0,18168,183955,3,4,32,1151585,5662,730,224,3657,1448,206,3204,10,1226,364,813,113,573,155,421,241,383,246,5,1354,196,210,581,707,23,1195,966,137,134,9,140,116,3,346,381,162,1122460,1197772,377,78,329040,1294,12383,4855,32692,15247,864,28687,9188,8384,4859,1361,9291,3023,3894,850,2646,5354,3033,1808,4020,978,4784,1,3146,5191,106,2054,920,873,1217,2975,6014,1,415,1141,6291,1221,2653,3222,4517,2777,920,2276,8,85,2711,1594,422,742,114,2212,531,148,1103,840,124,393,1137,278,107,157,635,3466,312,1132,4,3,2669,1839,184,1777,143,377,1947,2229,93,328,1284,16,2927,2247,473,1339,748,1039,2273,1,955,2844,6,6068,6286,4454,642,2450,2458,1226,1742,3655,1274,108,591,1119,1697,908,2,940,553,420,123,1519,2398,2895,2523,2049,842,1337,1098,3,346,230,970,865,7,371,2172,1368,707,148,43,146,1666,1647,502,1,957,1028,28,130,1,2089,4,59,1262,2668,83,1010,651,4,1528,17,924,733,630,1236,271,874,395,2,8,42,1798,20,445,1650,331,41,800,195,722,10,42,103,39,72,519,591,92,1884,43,495,804,210,503,640,574,16,126,1468,742,1,251,426,1588,89,585,19,889,237,284,1266,1263,163,93,70,211,533,95,875,11,757,3,36,42,328,232,912,233,22,30,449,59,1,221,282,939,2,1,1,557,272,15,656,54,927,586,401,2,27,249,120,126,399,2,2,51,154,41,109,326,555,33,3,286,5803216,3455,8797137,1324,549,333,444,1,2,80,1,900,896,1,8,1,2,2551,1,748,141,59,736,563,1,4265,1,1,1,1,137,1,879,9,305,2661,20,24,1,5,3,3,2,3389559,113465,20458660,41,2682692',kBL:'-5Vv'};google.sn='webhp';google.kHL='en-IN';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var c;a&&(!a.getAttribute||!(c=a.getAttribute("eid")));)a=a.parentNode;return c||google.kEI};google.getLEI=function(a){for(var c=null;a&&(!a.getAttribute||!(c=a.getAttribute("leid")));)a=a.parentNode;return c};google.ml=function(){return null};google.time=function(){return Date.now()};google.log=function(a,c,b,d,g){if(b=google.logUrl(a,c,b,d,g)){a=new Image;var e=google.lc,f=google.li;e[f]=a;a.onerror=a.onload=a.onabort=function(){delete e[f]};google.vel&&google.vel.lu&&google.vel.lu(b);a.src=b;google.li=f+1}};google.logUrl=function(a,c,b,d,g){var e="",f=google.ls||"";b||-1!=c.search("&ei=")||(e="&ei="+google.getEI(d),-1==c.search("&lei=")&&(d=google.getLEI(d))&&(e+="&lei="+d));d="";!b&&google.cshid&&-1==c.search("&cshid=")&&"slh"!=a&&(d="&cshid="+google.cshid);b=b||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+c+e+f+"&zx="+google.time()+d;/^http:/i.test(b)&&"https:"==window.location.protocol&&(google.ml(Error("a"),!1,{src:b,glmm:1}),b="");return b};}).call(this);(function(){google.y={};google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};}).call(this);google.f={};(function(){ ..........................................................................................................................................................................................
Example 4: How to get the HTTP Headers of a URL
If you only want to see the HTTPS headers of a URL then you need to use below curl command. In this example, we are trying to get the Headers of google.com
using curl -I https://www.google.com
command.
[root@localhost ~]# curl -I https://www.google.com HTTP/1.1 200 OK Content-Type: text/html; charset=ISO-8859-1 P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." Date: Sat, 13 Jun 2020 09:51:17 GMT Server: gws X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Transfer-Encoding: chunked Expires: Sat, 13 Jun 2020 09:51:17 GMT Cache-Control: private Set-Cookie: 1P_JAR=2020-06-13-09; expires=Mon, 13-Jul-2020 09:51:17 GMT; path=/; domain=.google.com; Secure Set-Cookie: NID=204=S4jJbhxc1OPMs3XYMrJW5_djdpmR_G23m7F0BodWvCN123Mw8BcO2wqQ9BmRWe8RE93U9NxDH6ngRaqCBnJ6Xux5DiY9LpKJykDfJfveCpwdzskmiP_r7O7ej1fy4HjGEwEsym_XBYTJRAcOF_Bvqjk5aOzLqVra7aC1h8v3lEk; expires=Sun, 13-Dec-2020 09:51:17 GMT; path=/; domain=.google.com; HttpOnly Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
-I : Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document.
Example 5: How to follow URL Redirect until the Destination
If you want to follow the redirection until the destination then you need to use -L
option with curl command. In this example, we are trying to follow the redirection of google.com
till its destination using curl -L google.com
command as shown below.
[root@localhost ~]# curl -L google.com <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-IN"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="XmH5rIaBuIvvJymfM9Zw5A==">(function(){window.google={kEI:'AaLkXraLJsT8wAO6h7TQAQ',kEXPI:'0,202123,3,4,32,1151585,5662,730,224,5104,207,2415,701,88,10,169,1057,364,1499,156,420,36,205,383,246,5,971,383,196,1126,5,367,1218,966,137,283,116,3,80,267,53,327,1122622,1197740,151,258,78,329040,1294,12383,4855,32692,15247,867,17444,11240,9188,8384,4858,1362,9290,3026,3892,850,11033,1808,4020,978,4784,1,3146,5297,2054,920,873,1217,2975,2692,3322,1,415,1141,6291,1221,2653,3221,4518,2779,917,2277,8,3683,706,1165,114,2212,530,149,1103,840,517,1137,278,107,792,3466,312,1132,4,3,2063,606,1839,184,544,1233,143,378,1703,242,2220,103,328,1284,16,2260,667,2247,473,1339,748,1039,3227,2372,473,9,6066,6286,4455,641,2449,2459,1226,1405,338,3654,1274,108,591,1119,1697,908,2,1483,430,1642,2397,5419,2049,842,1337,1098,3,346,230,970,865,7,366,3547,704,149,189,3313,502,1,1985,28,130,1,2093,60,3929,1101,643,4,499,806,143,80,17,416,509,352,1010,217,1019,271,874,395,2,8,41,1798,21,245,200,1075,575,331,41,15,785,195,722,9,146,111,1202,1884,43,77,1222,213,500,640,590,1593,743,1,254,424,357,1230,86,3,585,19,149,740,237,1550,1426,76,19,67,212,533,95,1645,37,27,14,329,212,20,621,291,232,8,45,508,1,221,30,7,245,500,1001,270,15,657,54,1751,163,2,669,11,241,3,2,1,50,153,316,2,1,1,156,386,1,3,154,41,28,23,25,5803432,8801916,549,333,444,1,2,80,1,900,896,1,8,1,2,2551,1,748,141,59,736,563,1,4265,1,1,1,1,137,1,879,9,305,2529,132,20,24,1,5,3,3,2,3389559,20572125,41,2682692',kBL:'-5Vv'};google.sn='webhp';google.kHL='en-IN';})();(function(){google.lc=[];google.li=0;google.getEI=function(a){for(var c;a&&(!a.getAttribute||!(c=a.getAttribute("eid")));)a=a.parentNode;return c||google.kEI};google.getLEI=function(a){for(var c=null;a&&(!a.getAttribute||!(c=a.getAttribute("leid")));)a=a.parentNode;return c};google.ml=function(){return null};google.time=function(){return Date.now()};google.log=function(a,c,b,d,g){if(b=google.logUrl(a,c,b,d,g)){a=new Image;var e=google.lc,f=google.li;e[f]=a;a.onerror=a.onload=a.onabort=function(){delete e[f]};google.vel&&google.vel.lu&&google.vel.lu(b);a.src=b;google.li=f+1}};google.logUrl=function(a,c,b,d,g){var e="",f=google.ls||"";b||-1!=c.search("&ei=")||(e="&ei="+google.getEI(d),-1==c.search("&lei=")&&(d=google.getLEI(d))&&(e+="&lei="+d));d="";!b&&google.cshid&&-1==c.search("&cshid=")&&"slh"!=a&&(d="&cshid="+google.cshid);b=b||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+c+e+f+"&zx="+google.time()+d;/^http:/i.test(b)&&"https:"==window.location.protocol&&(google.ml(Error("a"),!1,{src:b,glmm:1}),b="");return b};}).call(this);(function(){google.y={};google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};}).call(this);google.f={};(function()
-L : If the server reports that the requested page has moved to a different location, this option will make curl redo the request on the new place.
Example 6: How to Download a File using curl command
If you want to download a file then you need to use -O
option with curl command. In this example, we are trying to download CentOS.iso
image using below specified curl command. Please note that here we are using #
prompt as progress bar to track the percentage of download instead of using default progress bar.
[root@localhost ~]# curl -# -O http://centos.mirrors.estointernet.in/7.8.2003/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.iso ############## 19.5%
-# : Make curl display progress as a simple progress bar instead of the standard
-O : Write output to a local file named like the remote file we get.
Example 7: How to Resume a File Download using curl command
If you want to resume a file download which was stopped due to some reason then you need to use -C
option with curl command as shown below. In this example, we are trying to resume CentOS ISO download which was stopped due to some reason.
[root@localhost ~]# curl -# -C - -O http://centos.mirrors.estointernet.in/7.8.2003/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.iso ############### 25.5%
-C : Continue/Resume a previous file transfer at the given offset.
Example 8: How to Save a File with different File Name
If you want to save downloaded file with different name then you need to use -o
option with curl command as shown below. In this example, we are trying to save CentOS Image file with the name CentOS.ISO
as specified below.
[root@localhost ~]# curl -# -o CentOS.ISO -O http://centos.mirrors.estointernet.in/7.8.2003/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.iso ############### 18.7% [root@localhost ~]# ls -lrt CentOS.ISO -rw-r--r-- 1 root root 146669568 Jun 13 06:25 CentOS.ISO
-o : Write output to <file> instead of stdout.
Example 9: How to Limit the Transfer Rate
If you want to limit the data transfer rate then you need to use --limit-rate
option as shown below. In this example, we are trying to download CentOS ISO image file with a limit transfer rate of 254K
using curl command as shown in the below output.
[root@localhost ~]# curl --limit-rate 254k -# -O http://centos.mirrors.estointernet.in/7.8.2003/isos/x86_64/CentOS-7-x86_64-NetInstall-2003.iso ####### 5.7%
--limit-rate : Specify the maximum transfer rate you want curl to use.
Example 10: How to Access Protected FTP Server
If you want to access some FTP Server protected by username and password then you need to pass the credentials with -u
option as shown below. In this example, we are trying to List the contents of 192.168.0.103
Server by using curl -u centos:test@123 ftp://192.168.0.103
command where user name is centos
and password is test@123
.
[root@localhost ~]# curl -u centos:test@123 ftp://192.168.0.103 -rw-r--r-- 1 1000 1000 0 Apr 27 02:37 example.txt drwxrwxr-x 2 1000 1000 6 Apr 27 00:43 file lrwxrwxrwx 1 0 0 8 Apr 28 04:09 file.txt -> file.txt -rw-r--r-- 1 1000 1000 0 Jun 13 15:23 output.txt
Example 11: How to upload a File to the FTP Server
If you want to upload a file in the FTP Server then you need to use -T
option and specify the file name which you want to upload as shown below. In this example, we are trying to upload CentOS.iso
Image to FTP Server 192.168.0.103
using below curl command.
[root@localhost ~]# curl -# -T CentOS.ISO -u centos:test@123 ftp://192.168.0.103 ######################################################################## 100.0%
Now check the uploaded file and confirm.
[root@localhost ~]# curl -u centos:test@123 ftp://192.168.0.103 -rw-r--r-- 1 1000 1000 146669568 Jun 13 15:24 CentOS.ISO -rw-r--r-- 1 1000 1000 0 Apr 27 02:37 example.txt drwxrwxr-x 2 1000 1000 6 Apr 27 00:43 file lrwxrwxrwx 1 0 0 8 Apr 28 04:09 file.txt -> file.txt -rw-r--r-- 1 1000 1000 0 Jun 13 15:23 output.txt
-T : This transfers the specified local file to the remote URL.
-u : Specify the user name and password to use for server authentication.
Example 12: How to Pass Header Information
If you want to pass some header information with the URL then you need to use -H
option with curl command as shown below. In this example, we are trying to pass header information with parameter Upgrade-Insecure-Requests
equal to 1
while trying to access https://google.com
URL as specified below.
[root@localhost ~]# curl -I -H "Upgrade-Insecure-Requests:1" https://google.com HTTP/1.1 301 Moved Permanently Location: https://www.google.com/ Content-Type: text/html; charset=UTF-8 Date: Sat, 13 Jun 2020 21:45:48 GMT Expires: Mon, 13 Jul 2020 21:45:48 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 220 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
-H : Extra header to use when getting a web page. You may specify any number of extra headers.
Example 13: How to forcefully Use different SSL version
If you want to force curl to use some specific SSL version when negotiating with remote SSL Server then you need to pass that version with curl command. In this example, we are trying to use SSLV1
while trying to access https://google.com
.
[root@localhost ~]# curl -I -sslv1 https://google.com * About to connect() to google.com port 443 (#0) * Trying 172.217.25.14... * Connected to google.com (172.217.25.14) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 * Server certificate: * subject: CN=*.google.com,O=Google LLC,L=Mountain View,ST=California,C=US * start date: May 26 15:35:06 2020 GMT * expire date: Aug 18 15:35:06 2020 GMT * common name: *.google.com * issuer: CN=GTS CA 1O1,O=Google Trust Services,C=US > HEAD / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: google.com > Accept: */* > < HTTP/1.1 301 Moved Permanently HTTP/1.1 301 Moved Permanently < Location: https://www.google.com/ Location: https://www.google.com/ < Content-Type: text/html; charset=UTF-8 Content-Type: text/html; charset=UTF-8 < Date: Sat, 13 Jun 2020 21:48:09 GMT Date: Sat, 13 Jun 2020 21:48:09 GMT < Expires: Mon, 13 Jul 2020 21:48:09 GMT Expires: Mon, 13 Jul 2020 21:48:09 GMT < Cache-Control: public, max-age=2592000 Cache-Control: public, max-age=2592000 < Server: gws Server: gws < Content-Length: 220 Content-Length: 220 < X-XSS-Protection: 0 X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN X-Frame-Options: SAMEORIGIN < Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" < * Connection #0 to host google.com left intact
-sslv1 : Use SSL V1
Example 14: How to enable verbose mode
If you want to enable verbose mode then you need to use -v
option as shown below. In this example, we are trying to access google.com
using curl command with verbose mode enabled.
[root@localhost ~]# curl -v https://google.com * About to connect() to google.com port 443 (#0) * Trying 216.58.200.14... * Connected to google.com (216.58.200.14) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * SSL connection using TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 * Server certificate: * subject: CN=*.google.com,O=Google LLC,L=Mountain View,ST=California,C=US * start date: May 26 15:35:06 2020 GMT * expire date: Aug 18 15:35:06 2020 GMT * common name: *.google.com * issuer: CN=GTS CA 1O1,O=Google Trust Services,C=US > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: google.com > Accept: */* > < HTTP/1.1 301 Moved Permanently < Location: https://www.google.com/ < Content-Type: text/html; charset=UTF-8 < Date: Sat, 13 Jun 2020 21:54:16 GMT < Expires: Mon, 13 Jul 2020 21:54:16 GMT < Cache-Control: public, max-age=2592000 < Server: gws < Content-Length: 220 < X-XSS-Protection: 0 < X-Frame-Options: SAMEORIGIN < Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" < <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="https://www.google.com/">here</A>. </BODY></HTML> * Connection #0 to host google.com left intact
-v : Makes the fetching more verbose/talkative. Mostly useful for debugging.
Example 15: How to use specific interface to connect remote host
If you want to use some specific interface to connect remote host then you need to specify the interface name with --interface
option as shown below. In this example, we are trying to access google.com
using interface enp0s3
.
[root@localhost ~]# curl -I --interface enp0s3 https://google.com HTTP/1.1 301 Moved Permanently Location: https://www.google.com/ Content-Type: text/html; charset=UTF-8 Date: Sat, 13 Jun 2020 21:56:56 GMT Expires: Mon, 13 Jul 2020 21:56:56 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 220 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Alt-Svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
--interface : Perform an operation using a specified interface.
Example 16: How to Append the File instead of rewriting using curl command
If you want to append the file instead of uploading entire file again then you need to use -a
option with curl command as shown below.
[root@localhost ~]# curl -# -a -T CentOS.ISO -u centos:Harmony@123 ftp://192.168.0.103 ######################################################################## 100.0%
Now if you check the contents of FTP Server you can see that timestamp of CentOS.ISO
file is not changed.
[root@localhost ~]# curl -u centos:Harmony@123 ftp://192.168.0.103 -rw-r--r-- 1 1000 1000 440008704 Jun 13 22:00 CentOS.ISO -rw-r--r-- 1 1000 1000 0 Apr 27 02:37 example.txt drwxrwxr-x 2 1000 1000 6 Apr 27 00:43 file lrwxrwxrwx 1 0 0 8 Apr 28 04:09 file.txt -> file.txt -rw-r--r-- 1 1000 1000 0 Jun 13 15:23 output.txt [root@localhost ~]# date Sat Jun 13 18:01:08 EDT 2020
-a : When used in an upload, this will tell curl to append to the target file instead of overwriting it.
-T : This transfers the specified local file to the remote URL.
Example 17: How to Connect through Proxy Server
If you want to connect remote server using proxy server then you need to use below curl command. In this example, we are trying to connect https://google.co.in
through proxy server 192.168.0.103
using curl -x 192.168.0.103:3080 https://google.co.in
command as shown below.
[root@localhost ~]# curl -x 192.168.0.103:3080 https://google.co.in
-x : Use the specified HTTP proxy. If the port number is not specified, it is assumed at port 1080.
Example 18: How to check the meaning of a word from Dictionary
If you want to check the meaning of some word from dictionary then you need to use below command. In this example, we are trying to find out the meaning of word host from dictionary using curl dict://dict.org/d:host
command as shown below.
[root@localhost ~]# curl dict://dict.org/d:host 220 pan.alephnull.com dictd 1.12.1/rf on Linux 4.4.0-1-amd64 <auth.mime> <121444114.15615.1592087605@pan.alephnull.com> 250 ok 150 5 definitions retrieved 151 "Host" gcide "The Collaborative International Dictionary of English v.0.48" Host \Host\ (h[=o]st), n. [LL. hostia sacrifice, victim, from hostire to strike.] (R. C. Ch.) The consecrated wafer, believed to be the body of Christ, which in the Mass is offered as a sacrifice; also, the bread before consecration. [1913 Webster] Note: In the Latin Vulgate the word was applied to the Savior as being an offering for the sins of men. [1913 Webster] . 151 "Host" gcide "The Collaborative International Dictionary of English v.0.48" Host \Host\, v. t. To give entertainment to. [Obs.] --Spenser. [1913 Webster] . 151 "Host" gcide "The Collaborative International Dictionary of English v.0.48" Host \Host\ (h[=o]st), n. [OE. host, ost, OF. host, ost, fr. L. hostis enemy, LL., army. See {Guest}, and cf. {Host} a landlord.] 1. An army; a number of men gathered for war. [1913 Webster] A host so great as covered all the field. --Dryden. [1913 Webster] 2. Any great number or multitude; a throng. [1913 Webster] And suddenly there was with the angel a multitude of the heavenly host praising God. --Luke ii. 13. [1913 Webster] All at once I saw a crowd, A host, of golden daffodils. --Wordsworth. [1913 Webster] . 151 "Host" gcide "The Collaborative International Dictionary of English v.0.48" Host \Host\, v. i. To lodge at an inn; to take up entertainment. [Obs.] "Where you shall host." --Shak. [1913 Webster] . 151 "Host" gcide "The Collaborative International Dictionary of English v.0.48" Host \Host\ (h[=o]st), n. [OE. host, ost, OF. hoste, oste, F. h[^o]te, from L. hospes a stranger who is treated as a guest, he who treats another as his guest, a hostl prob. fr. hostis stranger, enemy (akin to E. guest a visitor) + potis able; akin to Skr. pati master, lord. See {Host} an army, {Possible}, and cf. {Hospitable}, {Hotel}.] 1. One who receives or entertains another, whether gratuitously or for compensation; one from whom another receives food, lodging, or entertainment; a landlord. --Chaucer. "Fair host and Earl." --Tennyson. [1913 Webster] Time is like a fashionable host, That slightly shakes his parting guest by the hand. --Shak. [1913 Webster] 2. (Biol.) Any animal or plant affording lodgment or subsistence to a parasitic or commensal organism. Thus a tree is a host of an air plant growing upon it. [Webster 1913 Suppl.] . 250 ok [d/m/c = 5/0/20; 0.000r 0.000u 0.000s] 221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s]
Example 19: How to send mail using SMTP Protocol
If you want to send mail using SMTP Protocol then you can use below curl command. You also need to specify sender email address using --mail-from
option and recipient email address using --mail-rcpt
option.
[root@localhost ~]# curl --mail-from local@example.com --mail-rcpt global@example.com smtp://192.168.0.103
--mail-from : Specify a single address that the given mail should get sent from.
--mail-rcpt : Specify a single address that the given mail should get sent to.
Example 20: How to check other options of curl command
If you want to check all the other options available with curl command then you need to use curl --help
command as shown below.
[root@localhost ~]# curl --help Usage: curl [options...] <url> Options: (H) means HTTP/HTTPS only, (F) means FTP only --anyauth Pick "any" authentication method (H) -a, --append Append to target file when uploading (F/SFTP) --basic Use HTTP Basic Authentication (H) --cacert FILE CA certificate to verify peer against (SSL) --capath DIR CA directory to verify peer against (SSL) -E, --cert CERT[:PASSWD] Client certificate file and password (SSL) --cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL) --ciphers LIST SSL ciphers to use (SSL) --compressed Request compressed response (using deflate or gzip) -K, --config FILE Specify which config file to read --connect-timeout SECONDS Maximum time allowed for connection -C, --continue-at OFFSET Resumed transfer offset -b, --cookie STRING/FILE String or file to read cookies from (H) -c, --cookie-jar FILE Write cookies to this file after operation (H) --create-dirs Create necessary local directory hierarchy --crlf Convert LF to CRLF in upload --crlfile FILE Get a CRL list in PEM format from the given file