theshell.ch/site/pages/cmd/interm/curl.html

78 lines
2.3 KiB
HTML
Raw Normal View History

---
layout: page
category-page: intermediate
category-title: Intermediate commands
tags: curl download http client crawler request online
author: Claudio Maggioni
title: curl
---
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>.
<h3>Usage</h3>
<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:
Example: Download the contents of the page "example.com" to "file.html"
<pre>
curl example.com -o file.html
</pre>
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")
<pre>
curl -O en.wikipedia.org/wiki/Curl
</pre>
Example: Download the contents of the page "example.com" to "file.html"
<pre>
curl example.com -o file.html
</pre>
Example: Download the contents of the page "example.com" following location
redirects (<code>-L</code> flag)
<pre>
curl -O -L example.com
</pre>
Example: Download the contents of the page "example.com" resuming a previous attempt
(<code>-C</code> flag)
<pre>
curl -O -C example.com
</pre>
Example: Do an HTTP DELETE request to "example.com" with a custom header
(<code>-H</code> and <code>-X</code> flags)
<pre>
curl -H 'User-Agent: Tamagotchi' -X DELETE example.com
</pre>
Example: Print to <i>stdout</i> "example.com" making a request with HTTP basic
authentication (<code>-u</code> flag)
<pre>
curl -u bob:P@ssw0rd example.com
</pre>