How to use Curl in Linux : Curl Guide For beginners

Curl is a command line tool for getting or sending files using URL syntax. It is used 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, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. We can use curl for download files from internet, sending custom HTTP ( GET and POST ) request, as FPT client, sending e-mails etc. Curl can be used in many different and interesting ways. Some of the main features of curl is :

  • User Athentication
  • FTP uploading/Downloading
  • FTP resume
  • HTTP Post
  • SSL connections
  • Cookies Support
  • Retry failed download ( Resume )
  • Multiple URLs support
  • Bandwidth limiting
  • HTTP Proxy
  • HTTP Resume
  • HTTP persistent connections

Normally Curl comes with by-default installed in all linux based systems. But if its not installed on your system then you can easily install it by :
 sudo apt-get install curl
Now below we are going some basic uses of curl utility with examples.

1. To retrieve a website :
to save the output in a file we can redirect it to a file
 curl > w3.html
or we can use the '-o' flag
 curl -o w3.html
where w3.html is output file name. By the using '-O' we can save the file with index.html name.
 curl -O

2. Get the HTTP response header information of a website with '-I' flag
 curl -I

3. Download a File with curl :
 curl -o notepadpp.exe
The below command will download and save the file as its same name
 curl -O

4. Batch download multiple files :
 curl -O URL1 -O URL2
example :
 curl -O -O

5. Resume a Canceled Download
 curl -O
and for some reason the download is canceled, then to resume it use '-C' flag with another '-' sign
 curl -C - -O

6. Downloading  a file using proxy server

Sometimes some sites are blocked in region from access, so to download files from those sites you can use the proxy servers
 curl -x [proy_server] -O [file_url]
example :
 curl -x -O

7. Use Verbose mode '-v' for more information
 curl -v -O

8. Download file from FTP Server
 curl -u ftpuser:ftppass -O ftp://localserver/files/testc.exe

9. Upload files on FTP Server
 curl -u ftpuser:ftppass -T testbin.exe ftp://localserver/

10. HTTP Authentication in Curl

Some sites are require username and password in order to access its content (which can be done by edit the .htaccess file). So at this scenario we have to provide username and password :
 curl -u username:password URL
example :
 curl -u john:12345

Conclusion : 

So these are some basic use of Curl utility. In the next post are going to see some advance usage of curl.