Linux curl Command Explained with Examples

Introduction

Transferring data to and from a server requires tools that support the necessary network protocols. Linux has multiple tools created for this purpose, the most popular being curl and wget.

This tutorial will show you how to use the curl command and provide you with an exhaustive list of the available options.

What Is the curl Command?

curl (short for “Client URL”) is a command line tool that enables data transfer over various network protocols. It communicates with a web or application server by specifying a relevant URL and the data that need to be sent or received.

curl is powered by libcurl, a portable client-side URL transfer library. You can use it directly on the command line or include it in a script. The most common use cases for curl are:

1、Downloading files from the internet
2、Endpoint testing
3、Debugging
4、Error logging

curl Syntax

The basic curl syntax is as follows:

1
curl [options/URLs]

For example:

1
curl https://www.gnu.org/gnu/gnu.html

If you specify a URL that leads to a file, you can use curl to download the file to your local system:

1
curl [url] > [local-file]

The syntax of URLs that are part of the command depends on the protocol. Multiple URLs that differ in one part are written together using braces:

1
http://example.{first,second,third}.com

Alphanumeric series are written with brackets:

1
ftp://ftp.url.com/file[1-100].txt

While nested sequences are not supported, multiple sequences are allowed:

1
http://url.com/archive[2010-2020]/vol[1-4]/part{a,b,c}.html

curl Protocols

curl supports numerous protocols for data transfer. Find the complete list below.

Protocol Description
DICT A dictionary network protocol for querying dictionary servers about the meanings of words.
FILE A URL scheme for obtaining a file from the local file system using curl.
FTP, FTPS File Transfer Protocol, used for file transfers between clients and servers. FTPS is the version of the same protocol with an added SSL/TLS security layer.
GOPHER, GOPHERS An old protocol for searching, retrieving, and distributing internet documents, a precursor of HTTP. GOPHERS is the version of the same protocol with an added SSL/TLS security layer.
HTTP, HTTPS Hypertext Transfer Protocol, used for web and internet data transfer. HTTPS is the version of the same protocol with an added SSL/TLS security layer.
IMAP, IMAPS Internet Message Access Protocol, used for email access and management. IMAPS is the version of the same protocol with an added SSL/TLS security layer.
LDAP, LDAPS Lightweight Directory Access Protocol, used for distributed directory information access and management. LDAPS is the version of the same protocol with an added SSL/TLS security layer.
MQTT Message Queuing Telemetry Transport - a protocol for data exchange between small devices, usually IoT systems.
POP3, POP3S Post Office Protocol version 3 - a protocol for email retrieval from a server. POP3S is the version of the same protocol with an added SSL/TLS security layer.
RTMP Real-Time Messaging Protocol - a streaming protocol for audio, video, and other data.
RTSP Real Time Streaming Protocol, used for streaming media servers management.
SCP Secure Copy - a protocol for copying files to and from an SSH server.
SFTP SSH File Transfer Protocol - a version of the File Transfer Protocol using the SSH connection.
SMB, SMBS Server Message Block - a protocol for managing shared access to files and computer peripherals. SMBS is the version of the same protocol with an added SSL/TLS security layer.
SMTP, SMPTS Simple Mail Transfer Protocol - an email protocol for easy transmission of email. SMTPS is the version of the same protocol with an added SSL/TLS security layer.
TELNET An application layer protocol for bidirectional interactive text-oriented communication.
TFTP Trivial File Transfer Protocol, used for uploading or downloading files to or from a remote host.

curl Command Options

curl accepts a wide array of options, which makes it an extremely versatile command. Options start with one or two dashes. If they do not require additional values, the single-dash options can be written together. For example, the command that utilizes the -O, -L, and -v options can be written as:

1
curl -OLv [url]

The list of all the available options is given below.

Option Description
–abstract-unix-socket Connect through abstract Unix socket instead through a network. Example: curl –abstract-unix-socket socketpath https://example.com
–alt-svc Enable alt-svc parser Example: curl –alt-svc svc.txt https://example.com

man curl or curl –manual

use man curl or curl –manual for see many command and options

Referce

Curl Official
Curl Github