Linux curl Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-curl-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Simply curl or command line tool and library for transferring data with URLs. curl provides wide range of support to download files and folders with command line interface. curl can be used with a lot of different type 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. curl supports 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 examples about curl where we look them one by one.

Syntax

Syntax of the curl command is like below.

Man

Man page of curl can be get with the following command

Man

Man

Help

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

Help

Help

Fetch And Display with HTTP/s

One of the most used type 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 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 bash redirect feature like below. In this example we can see some statistics information about the download. This information provides total size, received, average download speed, total time and times spend for download.

LEARN MORE  How To List All Partitions Of A Disk In Linux

Download with HTTP/s and Redirect

Download with HTTP/s and Redirect

Download with HTTP/s

There is a parameter used to save 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 those resides 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 this files like following example.

Set SSL Version

While using secure protocols like HTTPS, FTPS, POP3S SSL protocol will be used to create encrypted channel. SSL have 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 a of operations that occurs background. There will be also problems those we can not know what is happening. curl can provide details about the operations with the -v parameter like below.

LEARN MORE  How To Download, Install Packet Tracer Into Windows?

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 stateless protocol. To preserve user session cookies are used. While using HTTP protocol existing cookies can be used with -b parameter like below.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-curl-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

2 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 […]

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)