事实上每个Unix系统都预装了curl命令。curl允许我们模拟任何HTTP请求,然而通过命令行方式下载文件和网页是它最常用的功能。
  Virtually every Unix system comes with the curl command pre-installed. curl allows us to simulate any HTTP request, although most commonly it’s used to download files and webpages from the command-line.
        下面是个小例子:
  Here’s a quick example:

$ curl http://google.com
<HTML><HEAD>
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF=”http://www.google.com/”>here</A>.
</BODY></HTML>
$

        这里,curl抓取http://google.com的内容并打印输出任何我们收到的东西作为回应。这种情况下,我们收到一个让我们去往http://www.google.com的HTML文档。一般浏览器会自动跳转这个重定向,所以作为用户我们从不会看见这个页面。
  Here, curl is fetching the contents of http://google.com and printing out whatever we receive in response. In this case, we receive an HTML document telling us go to http://www.google.com instead. A normal browser would follow this redirect automatically, so as a user we’d never see this page.
        如果我们要求curl除了文本抓取其他东西,它仍会尝试将内容打印输出给终端,导致乱码。
  If we ask curl to fetch something other than text it will still try to print out its contents to the console, resulting in gibberish.

        保存curl的输出
  Saving Output From curl

        主要有两种方法保存curl输出:用>重定向或者加上 -o参数。
  There are two main ways to save the output from curl: using > redirection or using the -o option.

$ curl http://foo.com/bar.mp3 > song.mp3
$ curl -o song.mp3 http://foo.com/bar.mp3

        这两个方法都使curl下载bar.mp3并将它写入当前目录下的song.mp3文件。
  Both of these will result in curl downloading bar.mp3 and writing it to the song.mp3 file in the current directory.