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.
1 |
curl [options...] <url> |
Man
Man page of curl can get with the following command
1 |
$ man curl |

Man
Help
Simple fast help about parameters and options can get with the following command.
1 |
$ curl -h |

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.
1 |
$ curl https://www.poftut.com |

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.
1 |
$ curl https://www.poftut.com > poftut.html |

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
1 |
$ curl -o poftut.html https://www.poftut.com |

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
1 |
$ curl --limit-rate 1k -o poftut.html https://www.poftut.com |

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.
1 |
$ curl ftp://www.poftut.com/backup[1-9].tar |
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.
1 |
$ curl --sslv2 -o poftut.html https://www.poftut.com |

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.
1 |
$ curl --ssl -v -o poftut.html https://www.poftut.com |

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.
1 |
$ curl -s -o poftut.html https://www.poftut.com |
Specify User and Password
While using authentication required protocols and servers curl can provide these credentials like username and password.
1 |
$ curl -u ismail:mypassword -o data.tar ftp://poftut.com/backup.tar |
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.
1 |
$ curl -b aerf34fawfeawf -o statistics.html https://www.poftut.com/statistics.html |
3 Responses
[…] Curl is alternative to wget. To read curl tutorial click this link […]
[…] Linux curl Command Tutorial With Examples […]
[…] 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 […]