Curl是一个命令行实用程序,用于从远程服务器或向远程服务器传输数据。它允许您使用HTTP,HTTPS,SCP,SFTP和FTP协议下载或上传数据。

如果您尝试使用来下载文件,curl并收到一条错误消息,提示curl command not found您仅表示该curl软件包未安装在您的Debian系统上。

本教程介绍了如何curl在Debian 10 Buster上安装和使用命令。

在Debian上安装Curl

Curl软件包包含在默认的Debian 10存储库中,要安装它,请运行以下命令:

sudo apt install curl

要确认curl已安装,请输入curl您的终端,然后按Enter:

curl

该命令将输出以下输出:

curl: try \'curl --help\' or \'curl --manual\' for more information

而已!您已成功curl在Debian机器上安装,然后就可以开始使用它了。

使用卷曲

不带任何选项使用时curl,将指定为参数的URL的源代码输出到标准输出:

curl https://example.com

要下载带有curl的文件,请使用-o或-O标志。

小写-o选项允许您指定保存文件的名称:

curl -o linux.tar.xz https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

大写形式-O使用原始文件名保存文件:

curl -O https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.5.tar.xz

Curl的另一个有用功能是它能够显示给定URL的HTTP标头:

curl -I https://www.debian.org/
HTTP/1.1 200 OK
Date: Mon, 09 Sep 2019 21:22:30 GMT
Server: Apache
Content-Location: index.en.html
Vary: negotiate,accept-language,Accept-Encoding,cookie
TCN: choice
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
Referrer-Policy: no-referrer
X-Xss-Protection: 1
Strict-Transport-Security: max-age=15552000
Last-Modified: Mon, 09 Sep 2019 08:52:31 GMT
ETag: \"38e4-5921ae8851520\"
Accept-Ranges: bytes
Content-Length: 14564
Cache-Control: max-age=86400
Expires: Tue, 10 Sep 2019 21:22:30 GMT
X-Clacks-Overhead: GNU Terry Pratchett
Content-Type: text/html
Content-Language: en

使用Curl,您还可以从FTP服务器下载受密码保护的文件:

curl -u FTP_USERNAME:FTP_PASSWORD ftp://ftp.example.com/file.tar.gz