curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
curl offers a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer resume, Metalink, and more. The number of features will make your head spin!
How to use curl - general usage
# syntaxcurl<OPTIONS><URL>##### examples with parameterscurlhttp://127.0.0.1/test/test.php# gets the content of a file, but does not download anythingcurl -o /root/test/test-php.txt http://192.168.0.110/test/test.php # writes the output to the file test-php.txt in the directory /root/test/
##### Download multiple filescurl-Ohttp://mirrors.edge.kernel.org/archlinux/iso/2018.06.01/archlinux-2018.06.01-x86_64.iso \-Ohttps://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso##### Get HTTP headers of a URLcurl-I--http2https://www.ubuntu.com/##### test if a website supports http/2curl-I--http2-shttps://linuxize.com/|grepHTTP# support = HTTP/2 200# no support = HTTP/1.1 200 OK##### follow redirects# try curl google.com and curl -L google.com to see the differences.curl-Lgoogle.com##### change user agent (act as another browser)curl-A"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"https://getfedora.org/##### specify a maximum transfer rate (so you will decide how much data is going to be used at once to retrieve a file/page)
curl--limit-rate1m-Ohttps://dl.google.com/go/go1.10.3.linux-amd64.tar.gz# normally it will be the max your internet provider can handle, in above example it will be 1MB
How to use curl - cookies & proxies
# syntax = default##### send cookies with curlcurl -L -b "oraclelicense=a" -O http://download.oracle.com/otn-pub/java/jdk/10.0.2+13/19aef61b38124481863b1413dce1855f/jdk-10.0.2_linux-x64_bin.rpm
##### use proxy with curlcurl-x192.168.44.1:8888http://linux.com/# unauthenticated proxycurl-Uusername:password-x192.168.44.1:8888http://linux.com/# authenticated proxy
How to use curl - post requests
# syntax curl-XPOST<OPTIONS><URL>##### send data using the multipart/form-data content-typecurl-XPOST-F'name=linuxize'-F'email=linuxize@example.com'https://example.com/contact.php##### send data using the application/x-www-form-urlencoded content-typecurl-XPOST-d'name=linuxize'-d'email=linuxize@example.com'https://example.com/contact.phpcurl -X POST -d 'name=linuxize&email=linuxize@example.com' https://example.com/contact.php # If the -d option is used more than once you can merge the data using the & symbol
##### uploading an image/file (use multipart/form-data content-type)curl-XPOST-F'image=@/home/user/Pictures/wallpaper.jpg'http://example.com/upload
How to use curl - ftp usage
# syntax = default##### access a protected ftp server (this can also be done with the linux protocol tool : ftp)curl-uFTP_USERNAME:FTP_PASSWORDftp://ftp.example.com/##### download a file from the remote, protected ftp servercurl-uFTP_USERNAME:FTP_PASSWORDftp://ftp.example.com/file.tar.gz##### upload a file to the remote, protected ftp servercurl-Tnewfile.tar.gz-uFTP_USERNAME:FTP_PASSWORDftp://ftp.example.com/