Resources

  • curl manpage on Linux Die site.

Help

$ curl --help
  Usage: curl [options...] <url>
     --abstract-unix-socket <path> Connect via abstract Unix domain socket
     --alt-svc <file name> Enable alt-svc with this cache file
     ...
$ man curl
NAME
       curl - transfer a URL

SYNOPSIS
       curl [options / URLs]

DESCRIPTION
       curl  is a tool 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.

       curl  offers  a busload of useful tricks like proxy support, user authentication, FTP upload, HTTP post, SSL connections, cookies, file
       transfer resume, Metalink, and more. As you will see below, the number of features will make your head spin!

       curl is powered by libcurl for all transfer-related features. See libcurl(3) for details.
...

CLI

Usage


curl [OPTIONS...] URL

Flags

flag

description

example

-I, --head

Show headers only

“Show document info only”

-v

Verbose

-L

Follow redirects.

-H, --header HEADER

Request headers.

-H 'Content-Type: application/json'

-X, --request TYPE

Request type. Note that passing data with -d automatically generates a POST.

-X POST

-d, --data DATA

Pass data in a request. Typically JSON or form data in a POST.

--data 'foo=bar;bazz=123

--data '{"foo": "bar", "bazz": 123}' -H 'Content-Type: application/json'

-F FIELD=VALUE

Send field

-F 'foo=bar' 'bazz=123'

-u, --user USER:PASSWORD

Server user and password

-A, --user-agent NAME

Send User-Agent value

curl -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0" https://example.com/"

-O

Output file with resource’s name. No argument required. The name will be inferred from the URL - useful for when downloading a zip file for example.

curl https://example.com/abc/def.zip -O

Now it will be available as def.zip.

-o OUTPUT_PATH

Save resource with desired name.

curl https://example.com/abc/def.zip -o foo.zip

Files

Provide a path to a file.

Basic upload

curl -F 'upload=@my_file.txt' URL

Image

curl -F 'image=@my_image.png' URL

Headers

Protocol response headers.

Using -I flag, only the headers will be shown. No content.

This can be useful for debugging an API or a server-rendered page, where you don’t get about the content (which can be long).

e.g.

$ curl -I https://google.com
HTTP/2 301
location: https://www.google.com/
content-type: text/html; charset=UTF-8
date: Sat, 21 Aug 2021 12:24:24 GMT
expires: Mon, 20 Sep 2021 12:24:24 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"

Add headers

Using -i flag, you’ll see the headers added like date and content type.

Any other content like HTMl will be shown after it.

e.g.

$ curl -i https://google.com
location: https://www.google.com/
content-type: text/html; charset=UTF-8
date: Sat, 21 Aug 2021 12:22:33 GMT
expires: Mon, 20 Sep 2021 12:22:33 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 220
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>