Linux curl Command Tutorial With Examples – POFTUT

Linux curl Command Tutorial With Examples

Simply curl or command-line tool and library for transferring data with URLs. curl provides a wide range of support to download files and folders with a command-line interface. curl can be used with a lot of different types of protocols. Below are the protocols currently supported by curl.

  • DICT
  • FILE
  • FTP/FTPS
  • Gopher
  • HTTP
  • HTTPS
  • IMAP/IMAPS
  • LDAP/LDAPS
  • POP3/POP3S
  • RTMP
  • RTSP
  • SCP
  • SFTP
  • SMB
  • SMTP/SMTPS
  • Telnet and TFTP
  • SSL certificates
  • HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling

Keep your breath because there are a lot of examples about curl where we look at them one by one.

Syntax

The syntax of the curl command is like below.

Man

Man page of curl can get with the following command

Man

Man

Help

Simple fast help about parameters and options can get with the following command.

Help

Help

Fetch And Display with HTTP/s

One of the most used types of curl is downloading HTML or similar files with HTTP/s. curl will automatically detect the transfer protocol which is HTTPs in this example.

Fetch And Display with HTTP/s

Fetch And Display with HTTP/s

Download with HTTP/s and Redirect

In the previous example, the downloaded file is printed out the standard output which is our terminal. But this is generally not a practical usage. The downloaded file can be redirected to a file with a bash redirect feature like below. In this example, we can see some statistical information about the download. This information provides total size, received, average download speed, total time and times spend for download.

LEARN MORE  How To Release and Renew IP Address In Windows with Ip Release and Renew

Download with HTTP/s and Redirect

Download with HTTP/s and Redirect

Download with HTTP/s

There is a parameter used to save the downloaded file into a file with no extra command. This parameter is -o

Download with HTTP/s

Download with HTTP/s

Limit Download Rate

Another useful feature of curl is limiting download rate. This can be very useful in situations where there is limited internet bandwidth and it should be shared with other applications. In this examples, we have limited bandwidth to 1K and this will make our download take some time

Limit Download Rate

Limit Download Rate

Download Sequential Files

System administrators generally prefer using sequential file names for backups or similar operations. Also log files that reside in /var/log are generally names with sequentially. So downloading them one by one specifying the full name of the file is drudgery work. curl can download these files like the following example.

Set SSL Version

While using secure protocols like HTTPS, FTPS, POP3S SSL protocol will be used to create encrypted channels. SSL has a different version where this may create incompatible situations. SSL version can be specified with the --sslv2 and--sslv3 parameter. But keep in mind that curl uses GnuTLS library for cryptographic operations and GnuTLS should have support for SSLv2.

Set SSL Version

Set SSL Version

Verbose and Debug Mode

While downloading and uploading files with curl there will be operations that occur background. There will be also problems that we can not know what is happening. curl can provide details about the operations with the -v parameter like below.

LEARN MORE  What Is System Administrator and Duties ?

Verbose and Debug Mode

Verbose and Debug Mode

Silent Mode

There is another mode where there will be no output to the terminal. This can be used for clean download.

Specify User and Password

While using authentication required protocols and servers curl can provide these credentials like username and password.

Set Cookie

As we know HTTP is a stateless protocol. To preserve user session cookies are used. While using HTTP protocol existing cookies can be used with -b parameter like below.

3 Responses

  1. 07/03/2017

    […] Curl is alternative to wget. To read curl tutorial click this link […]

  2. 18/09/2017

    […] Linux curl Command Tutorial With Examples […]

  3. 30/10/2019

    […] make the API request to the XG using a browser or any remote application that support API like curl. Sophos XG Firewall: How to use API to import web exceptions is an […]

Leave a Reply

Your email address will not be published. Required fields are marked *