curl
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 |
---|---|---|
|
Show headers only “Show document info only” | |
|
Verbose | |
|
Follow redirects. | |
|
Request headers. |
|
|
Request type. Note that passing data with |
|
|
Pass data in a request. Typically JSON or form data in a POST. |
|
|
Send field |
|
|
Server user and password | |
|
Send User-Agent value |
|
|
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. |
Now it will be available as |
|
Save resource with desired name. |
|
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.
Head
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>