2018-11-14 17:56:45 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: intermediate
|
|
|
|
category-title: Intermediate commands
|
2018-11-14 21:15:38 +00:00
|
|
|
tags: curl download http client crawler request online
|
2018-11-14 17:56:45 +00:00
|
|
|
author: Claudio Maggioni
|
|
|
|
title: curl
|
2018-11-18 20:38:56 +00:00
|
|
|
previous-page: pages/cmd/interm/chroot.html
|
|
|
|
next-page: pages/cmd/interm/fg.html
|
2018-11-14 17:56:45 +00:00
|
|
|
---
|
2018-11-14 21:15:38 +00:00
|
|
|
The <code>curl</code> command is a fast and versatile shell program that can
|
|
|
|
request online content using various protocols, including <i>HTTP</i>,
|
|
|
|
<i>FTP</i> and <i>POP3</i>. Some example use cases for this utility are
|
|
|
|
the need to automate some remote call to a server, testing <i>REST</i> or
|
|
|
|
<i>SOAP</i> apis or simply download or display the <i>HTML</i> code of a
|
|
|
|
website.
|
|
|
|
|
|
|
|
The name, as mentioned in the <a href="https://ec.haxx.se/curl-name.html">
|
|
|
|
<i>Evertything curl</i></a> online book, stands for <i>"client URL"</i>
|
|
|
|
and the right pronunciation rhymes with "earl" or "girl". By this fact, the
|
|
|
|
reader is able to tell the author of this page to stop pronuncing it as
|
|
|
|
<i>"cooorl"</i>, like if the name is some sort of word in the
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Bergamasque_dialect"><i>Bergamasque
|
|
|
|
dialect</i></a>.
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<h3>Usage</h3>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
<code>curl</code> is a very complex command: if you want to learn it deeply,
|
|
|
|
please refer to the previously mentioned guide called
|
|
|
|
<a href="https://ec.haxx.se/"><i>Evertything curl</i></a>. Some basic
|
|
|
|
ways to use this command are shown below:
|
2018-11-14 17:56:45 +00:00
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Download the contents of the page "example.com" to "file.html"
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
curl example.com -o file.html
|
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Download the contents of the page "en.wikipedia.org/wiki/Curl" to
|
|
|
|
a file with the same name as the last element in the path (here "Curl")
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
curl -O en.wikipedia.org/wiki/Curl
|
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Download the contents of the page "example.com" to "file.html"
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
curl example.com -o file.html
|
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Download the contents of the page "example.com" following location
|
|
|
|
redirects (<code>-L</code> flag)
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-14 21:15:38 +00:00
|
|
|
curl -O -L example.com
|
2018-11-14 17:56:45 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Download the contents of the page "example.com" resuming a previous attempt
|
|
|
|
(<code>-C</code> flag)
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-14 21:15:38 +00:00
|
|
|
curl -O -C example.com
|
2018-11-14 17:56:45 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Do an HTTP DELETE request to "example.com" with a custom header
|
|
|
|
(<code>-H</code> and <code>-X</code> flags)
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
curl -H 'User-Agent: Tamagotchi' -X DELETE example.com
|
|
|
|
</pre>
|
|
|
|
|
2018-11-14 21:15:38 +00:00
|
|
|
Example: Print to <i>stdout</i> "example.com" making a request with HTTP basic
|
|
|
|
authentication (<code>-u</code> flag)
|
2018-11-14 17:56:45 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
curl -u bob:P@ssw0rd example.com
|
|
|
|
</pre>
|