Linux curl命令如何使用?用法示例介绍

2021年11月19日22:51:21 发表评论 1,271 次浏览

Linux curl命令使用教程介绍

Linux如何使用curl命令?与服务器之间传输数据需要支持必要网络协议的工具。Linux 有多种为此目的而创建的工具,最受欢迎的是 curl 和wget。

Linux curl命令如何使用本教程将向你展示如何使用该curl命令并为你提供可用选项的详尽列表。

先决条件

  • 访问终端
  • 互联网
  • curl安装

注意:如果你没有安装 curl,请在终端中键入以下内容进行安装:

sudo apt 安装curl

什么是 curl 命令?

curl(“客户端 URL”的缩写)是一个命令行工具,可以通过各种网络协议进行数据传输。它通过指定相关的 URL 和需要发送或接收的数据与Web 或应用程序服务器进行通信。

curl由 libcurl 提供支持,libcurl 是一个便携式客户端 URL 传输库。你可以直接在命令行上使用它或将其包含在脚本中。最常见的用例curl 是:

  • 从互联网下载文件
  • 端点测试
  • 调试
  • 错误记录

Linux curl命令用法示例:curl语法

基本curl语法如下:

curl [options/URLs]

例如:

curl https://www.gnu.org/gnu/gnu.html

Linux curl命令如何使用?系统输出在curl命令后提供的 URL 上找到的 HTML 内容。

Linux curl命令如何使用?用法示例介绍

Linux如何使用curl命令?如果指定指向文件的 URL,则可以使用curl将文件下载到本地系统:

curl [url] > [local-file]

进度条显示到目前为止已下载了多少文件。

Linux curl命令如何使用?用法示例介绍

作为命令一部分的 URL 的语法取决于协议。一个部分不同的多个 URL 使用大括号写在一起:

http://example.{first,second,third}.com

字母数字系列用括号表示:

ftp://ftp.url.com/file[1-100].txt

虽然不支持嵌套序列,但允许多个序列:

http://url.com/archive[2010-2020]/vol[1-4]/part{a,b,c}.html

Linux curl命令使用教程:curl协议

curl 支持多种数据传输协议。找到下面的完整列表。

协议描述
字典一个字典网络协议,用于向字典服务器查询单词的含义。
文件使用 curl 从本地文件系统获取文件的 URL 方案。
FTP、FTPS文件传输协议,用于客户端和服务器之间的文件传输。FTPS是相同协议的版本,增加了 SSL/TLS 安全层。
地鼠,地鼠一种用于搜索、检索和分发 Internet 文档的旧协议,是 HTTP 的前身。GOPHERS 是相同协议的版本,增加了SSL/TLS安全层。
HTTP、HTTPS超文本传输​​协议,用于网络和互联网数据传输。HTTPS 是相同协议的版本,但添加了 SSL/TLS 安全层。
IMAP, IMAPInternet 消息访问协议,用于电子邮件访问和管理。IMAPS 是相同协议的版本,增加了 SSL/TLS 安全层。
LDAP、LDAPS轻量级目录访问协议,用于分布式目录信息的访问和管理。LDAPS 是相同协议的版本,增加了 SSL/TLS 安全层。
MQTT消息队列遥测传输——一种用于小型设备(通常是物联网系统)之间数据交换的协议。
POP3、POP3S邮局协议版本 3 - 从服务器检索电子邮件的协议。POP3S 是相同协议的版本,增加了 SSL/TLS 安全层。
RTMP实时消息传递协议 - 音频、视频和其他数据的流协议。
实时服务提供商Real Time Streaming Protocol,用于流媒体服务器管理。
SCP安全复制 - 用于将文件复制到 SSH 服务器和从 SSH 服务器复制文件的协议。
SFTPSSH文件传输协议 - 使用 SSH 连接的文件传输协议的一个版本。
中小企业、中小企业服务器消息块 - 用于管理对文件和计算机外围设备的共享访问的协议。SMBS 是相同协议的版本,增加了 SSL/TLS 安全层。
SMTP、SMPTS简单邮件传输协议 - 一种用于轻松传输电子邮件的电子邮件协议。SMTPS 是相同协议的版本,增加了 SSL/TLS 安全层。
远程登录双向交互式文本导向通信的应用层协议。
TFTP普通文件传输协议,用于向远程主机上传文件或从远程主机下载文件。

curl 命令选项

Linux如何使用curl命令?curl接受广泛的选项,这使它成为一个非常通用的命令。选项以一两个破折号开头。如果它们不需要附加值,则可以将单破折号选项写在一起。例如,利用该命令-O-L-v选项可以写为:

curl -OLv [url]

Linux curl命令如何使用?下面给出了所有可用选项的列表。

选项描述
--abstract-unix-socket <path>通过抽象的 Unix 套接字而不是通过网络连接。

例子:
curl --abstract-unix-socket socketpath https://example.com
--alt-svc <file name>启用 alt-svc 解析器。

例子:
curl --alt-svc svc.txt https://example.com
--anyauthCurl 为给定的 HTTP URL 查找并使用最安全的身份验证方法。

例子:
curl --anyauth --user me:pass https://example.com
-a, --append附加到目标文件。

例子:
curl --upload-file local --append ftp://example.com/
--aws-sigv4 <provider1[:provider2[:region[:service]]]>使用 AWS V4 签名身份验证。

例子:
curl --aws-sigv4 "aws:amz:east-2:es" --user "key:secret" https://example.com
--basic使用 HTTP 基本身份验证。 

例子:
curl -u name:password --basic https://example.com
--cacert <file>使用指定的文件进行证书验证。

Linux curl命令用法示例:
curl --cacert CA-file.txt https://example.com
--capath <dir>使用指定的目录查找证书。

例子:
curl --capath /local/directory https://example.com
--cert-status验证服务器证书状态。

例子:
curl --cert-status https://example.com
--cert-type <type>指定所提供证书的类型。可识别的类型为PEM(默认)DERENG P12

例子:
curl --cert-type ENG --cert file https://example.com
-E, --cert <certificate[:password]>使用基于 SSL 的协议时使用提供的证书文件。

例子:
curl --cert certfile --key keyfile https://example.com
--ciphers <list of ciphers>提供要在连接中使用的密码。

例子:
curl --ciphers ECDHE-ECDSA-AES256-CCM8 https://example.com
--compressed-ssh启用内置 SSH 压缩。 

例子:
curl --compressed-ssh sftp://example.com/
--compressed请求接收压缩响应。 

例子:
curl --compressed https://example.com 
-K, --config <file>提供带有 curl 参数的文本文件,而不是将它们写在命令行上。 

例子:
curl --config file.txt https://example.com
--connect-timeout <fractional seconds>指定 curl 连接可以持续的最长时间。

例子:
curl --connect-timeout 30 https://example.com
--connect-to <HOST1:PORT1:HOST2:PORT2>提供连接规则以将请求定向到特定服务器集群节点。 

例子:
curl --connect-to example.com:443:example.net:8443 https://example.com
-C, --continue-at <offset>在指定的偏移量处恢复文件传输。

curl -C 400 https://example.com
-c, --cookie-jar <filename>指定用于存储 cookie 的文件。

curl -c store.txt https://example.com
-b, --cookie <data|filename>从文件中读取 cookie。 

例子:
curl -b cookiefile https://example.com
--create-dirs--output选项创建本地目录。 

例子:
curl --create-dirs --output local/dir/file https://example.com
--create-file-mode <mode>指定在创建文件时设置的模式。 

例子:
curl --create-file-mode 0777 -T localfile sftp://example.com/new
--crlf将 LF 转换为 CRLF。 

curl --crlf -T file ftp://example.com/
--crlfile <file>为对等证书提供证书吊销列表。 

curl --crlfile revoke.txt https://example.com
--curves <algorithm list>提供建立 SSL 会话的curl。

例子:
curl --curves X25519 https://example.com
--data-ascii <data>-d--data。 

例子:
curl --data-ascii @file https://example.com
--data-binary <data>按指定发布数据,无需额外处理。 

curl --data-binary @filename https://example.com
--data-raw <data>-d,相同--data,但 @ 字符的处理方式与其他字符没有区别。 

curl --data-raw "@at@at@" https://example.com
--data-urlencode <data>-d,相同--data,但执行 URL 编码。

例子:
curl --data-urlencode name=val https://example.com
-d, --data <data>在 POST 请求中将数据发送到 HTTP 服务器。  

例子:
curl -d "name=curl" https://example.com
--delegation <LEVEL>指定何时允许服务器委派凭据。 

例子:
curl --delegation "always" https://example.com
--digest启用 HTTP 摘要身份验证。 

例子:
curl -u name:password --digest https://example.com
--disable-eprt禁用用于活动 FTP 传输的 EPRT 和 LPRT 命令。 

例子:
curl --disable-eprt ftp://example.com/
--disable-epsv为被动 FTP 传输禁用 EPSV。

例子:
curl --disable-epsv ftp://example.com/
-q, --disable禁用读取 curlrc 配置文件。

curl -q https://example.com 
--disallow-username-in-url如果提供包含用户名的 URL,则退出。 

例子:
curl --disallow-username-in-url https://example.com
--dns-interface <interface>指定用于传出 DNS 请求的接口。 

例子:
curl --dns-interface eth0 https://example.com
--dns-ipv4-addr <address>指定 DNS 请求将来自的 IPv4 地址。 

例子:
curl --dns-ipv4-addr 10.1.2.3 https://example.com
--dns-ipv6-addr <address>指定 DNS 请求将来自的 IPv6 地址。 

例子:
curl --dns-ipv6-addr 2a04:4e42::561 https://example.com
--dns-servers <addresses>指定你自己的 DNS 服务器列表。 

例子:
curl --dns-servers 192.168.0.1,192.168.0.2 https://example.com
--doh-cert-status--cert-status用于 DNS-over-HTTPS。 

例子:
curl --doh-cert-status --doh-url https://doh.server https://example.com 
--doh-insecure-k--insecure对于 DoH。

例子:
curl --doh-insecure --doh-url https://doh.server https://example.com
--doh-url <URL>为主机名解析指定 DoH 服务器。 

例子:
curl --doh-url https://doh.server https://example.com 
-D, --dump-header <filename>指定用于写入协议头的文件。 

例子:
curl --dump-header store.txt https://example.com 
--egd-file <file>提供 EGD 插座的路径。 

例子:
curl --egd-file /path/here https://example.com 
--engine <name>指定 OpenSSL 加密引擎。

例子:
curl --engine flavor https://example.com  
--etag-compare <file>请求从文件中读取 ETag。

例子:
curl --etag-compare etag.txt https://example.com  
--etag-save <file>将 HTTP ETag 保存到文件。 

例子:
curl --etag-save etag.txt https://example.com 
--expect100-timeout <seconds>100-continue 响应的最长等待时间。 

例子:
curl --expect100-timeout 2.5 -T file https://example.com 
--fail-early当 curl 检测到传输中的第一个错误时,告诉 curl 失败并退出。 

例子:
curl --fail-early https://example.com https://two.example 
--fail-with-body如果服务器返回代码为 400 或更大的错误,curl 保存内容并返回错误 22。  

示例:
curl --fail-with-body https://example.com 
-f, --fail如果服务器返回错误,curl 会静默失败并返回错误 22。 

示例:
curl --fail https://example.com 
--false-start在 TLS 握手时使用错误启动。 

例子:
curl --false-start https://example.com 
--form-string <name=string>-F,类似--form,但按字面处理值字符串。 

例子:
curl --form-string "data" https://example.com 
-F, --form <name=content>使用已按下的提交按钮模拟表单。该@符号强制内容为文件。该<符号仅提取文件的内容部分。  

例子:
curl --form "name=curl" --form "file=@loadthis" https://example.com
--ftp-account <data>指定 FTP 服务器的帐户数据。 

例子:
curl --ftp-account "account_data" ftp://example.com/
--ftp-alternative-to-user <command>指定用户名密码认证失败时发送的命令。 

例子:
curl --ftp-alternative-to-user "U53r" ftp://example.com 
--ftp-create-dirs如果指定的目录不存在,curl 将尝试创建它。

例子:
curl --ftp-create-dirs -T file ftp://example.com/dirs/one/file 
--ftp-method <method>指定用于通过 FTP 获取文件的方法。可用的方法是multicwdnocwdsinglecwd。  

例子:
curl --ftp-method multicwd ftp://example.com/dir1/dir2/file 
--ftp-pasv使用被动数据连接模式。 

例子:
curl --ftp-pasv ftp://example.com/ 
-P, --ftp-port <address>反转 FTP 连接的默认角色。 

例子:
curl -P eth0 ftp:/example.com 
--ftp-pret在 PASV/EPSV 之前发送 PRET 命令。

例子:
curl --ftp-pret ftp://example.com/ 
--ftp-skip-pasv-ip不要使用服务器建议的 IP 地址。curl 将使用控制连接 IP。 

例子:
curl --ftp-skip-pasv-ip ftp://example.com/ 
--ftp-ssl-ccc-mode <active/passive>设置清除命令通道 (CCC) 模式。

例子:
curl --ftp-ssl-ccc-mode active --ftp-ssl-ccc ftps://example.com/ 
--ftp-ssl-ccc身份验证完成后,SSL/TLS 层被消除,允许未加密的通信。 

例子:
curl --ftp-ssl-ccc ftps://example.com/ 
--ftp-ssl-control使用 SSL/TLS 登录,数据传输开始时停止加密。

例子:
curl --ftp-ssl-control ftp://example.com 
-G, --get使用 HTTP GET 请求而不是 POST。 

例子:
curl --get -d "tool=curl" -d "age=old" https://example.com
-g, --globoff禁用 URL globbing 解析器。

例子:
curl -g "https://example.com/{[]}}}}"  
--happy-eyeballs-timeout-ms <milliseconds>使用 Happy Eyeballs 算法连接双栈主机。 

例子:
curl --happy-eyeballs-timeout-ms 500 https://example.com 
--haproxy-protocol使用 HAProxy PROXY 协议 v1 标头。 

例子:
curl --haproxy-protocol https://example.com 
-I, --head仅获取标题。

例子:
curl -I https://example.com 
-H, --header <header/@file>指定要在 HTTP 请求中发送的附加标头。 

例子:
curl -H "X-First-Name: Joe" https://example.com 
-h, --help <category>请参阅特定类别的帮助。all列出所有可用选项。 

例子:
curl --help all 
--hostpubmd5 <md5>传递 32 位十六进制字符串。 

例子:
curl --hostpubmd5 e5c1c49020640a5ab0f2034854c321a8 sftp://example.com/ 
--hsts <file name>启用 HSTS。 

例子:
curl --hsts cache.txt https://example.com 
--http0.9接受 HTTP 版本 0.9 响应。 

例子:
curl --http0.9 https://example.com
-0, --http1.0使用 HTTP 版本 1.0。 

例子:
curl --http1.0 https://example.com
--http1.1使用 HTTP 版本 1.1。   

例子:
curl --http1.1 https://example.com 
--http2-prior-knowledge使用 HTTP 2.0 版。如果你知道服务器支持此 HTTP 版本,请使用此选项。 

例子:
curl --http2-prior-knowledge https://example.com
--http2尝试使用 HTTP 2.0 版。 

例子:
curl --http2 https://example.com
--http3使用 HTTP 3.0 版。这是一个实验选项。   

例子:
curl --http3 https://example.com
--ignore-content-length忽略 Content-Length 标头。

例子:
curl --ignore-content-length https://example.com 
-i, --include指定输出应包含 HTTP 响应标头。 

例子:
curl -i https://example.com
-k, --insecure允许 curl 处理不安全的连接。 

例子:
curl --insecure https://example.com 
--interface <name>指定用于执行操作的接口。 

例子:
curl --interface eth0 https://example.com 
-4, --ipv4仅将名称解析为 IPv4 地址。 

例子:
curl --ipv4 https://example.com 
-6, --ipv6仅将名称解析为 IPv6 地址。

例子:
curl --ipv6 https://example.com
-j, --junk-session-cookies丢弃会话 cookie。 

例子:
curl --junk-session-cookies -b cookies.txt https://example.com 
--keepalive-time <seconds>指定连接在发送保活探测之​​前的空闲时间。 

例子:
curl --keepalive-time 30 https://example.com 
--key-type <type>指定私钥的类型。可用类型为PEM(默认)DER、 和ENG。 

例子:
curl --key-type ENG --key here https://example.com 
--key <key>指定包含私钥的文件。 

例子:
curl --cert certificate --key here https://example.com 
--krb <level>启用和使用 Kerberos 身份验证。可用级别为clearsafeconfidentialprivate (默认)。 

例子:
curl --krb clear ftp://example.com/ 
--libcurl <file>获取指定命令行操作的 C 源代码。 

例子:
curl --libcurl client.c https://example.com 
--limit-rate <speed>指定最大上传和下载传输速率。 

例子:
curl --limit-rate 100K https://example.com 
-l, --list-only强制仅名称视图。 

例子:
curl --list-only ftp://example.com/dir/ 
--local-port <num/range>指定用于连接的端口号。 

例子:
curl --local-port 1000-3000 https://example.com 
--location-trusted类似于-L--location,但允许你将名称和密码发送到所有重定向。

例子:
curl --location-trusted -u user:pass https://example.com
-L, --location允许 curl 跟随任何重定向。 

例子:
curl -L https://example.com 
--login-options <options>指定电子邮件服务器身份验证的登录选项。 

例子:
curl --login-options 'AUTH=*' imap://example.com 
--mail-auth <address>提供一个地址作为身份。 

例子:
curl --mail-auth user@example.come -T mail smtp://example.com/ 
--mail-from <address>提供一个“发件人”地址。

例子:
curl --mail-from user@example.com -T mail smtp://example.com/ 
--mail-rcpt-allowfails如果收件人之一失败,则允许 curl 继续进行 SMTP 对话。 

例子:
curl --mail-rcpt-allowfails --mail-rcpt dest@example.com smtp://example.com 
--mail-rcpt <address>提供一个“收件人”地址。  

例子:
curl --mail-rcpt user@example.net smtp://example.com 
-M, --manual阅读 curl 手册。 

例子:
curl --manual 
--max-filesize <bytes>提供要下载的文件的最大大小。  
例子:
curl --max-filesize 500K https://example.com 
--max-redirs <num>指定活动时的最大重定向数--location。 

例子:
curl --max-redirs 3 --location https://example.com 
-m, --max-time <fractional seconds>指定操作的最长时间。 

例子:
curl --max-time 5.52 https://example.com 
--metalink指定一个 metalink 资源。此选项在最新版本的 curl 中被禁用。 

例子:
curl --metalink file https://example.com 
--negotiate启用 SPNEGO 身份验证。 

例子:
curl --negotiate -u : https://example.com
--netrc-file <filename>类似于--n--netrc,但允许你指定要使用的文件。 

例子:
curl --netrc-file netrc https://example.com 
--netrc-optional--n--netrc,但使用 netrc 是可选的。 

例子:
curl --netrc-optional https://example.com 
-n, --netrc在 netrc 文件中搜索登录信息。

例子:
curl --netrc https://example.com 
-:, --next使用该选项来分隔 URL 请求。 

例子:
curl -I https://example.com --next https://example.net/ 
--no-alpn禁用 ALPN TLS 扩展。 

例子:
curl --no-alpn https://example.com 
-N, --no-buffer禁用输出流缓冲区。 

例子:
curl --no-buffer https://example.com 
--no-keepalive禁用保活消息。 

例子:
curl --no-keepalive https://example.com 
--no-npn禁用 NPN TLS 扩展。 

例子:
curl --no-npn https://example.com 
--no-progress-meter禁用进度条但显示任何其他消息。 

例子:
curl --no-progress-meter -o store https://example.com 
--no-sessionid禁用 SSL session-ID 的缓存。 

例子:
curl --no-sessionid https://example.com 
--noproxy <no-proxy-list>列出不应使用代理的主机。 

例子:
curl --noproxy "www.example" https://example.com 
--ntlm-wb--ntlm,但也将身份验证交给 ntlmauth。

例子:
curl --ntlm-wb -u user:password https://example.com  
--ntlm启用 NTLM 身份验证。 

例子:
curl --ntlm -u user:password https://example.com 
--oauth2-bearer <token>为 OAUTH 2.0 提供承载令牌。 

例子:
curl --oauth2-bearer "mF_9.B5f-4.1JqM" https://example.com 
--output-dir <dir>指定输出文件目录。

例子:
curl --output-dir "tmp" -O https://example.com 
-o, --output <file>将输出存储在文件中。输出未显示在标准输出中。 

例子:
curl -o file https://example.com -o file2 https://example.net 
--parallel-immediate比等待新连接或多路复用流更喜欢并行连接。 

例子:
curl --parallel-immediate -Z https://example.com -o file1 https://example.com -o file2
--parallel-max <num>指定最大并行连接数。 

Linux curl命令用法示例:
curl --parallel-max 100 -Z https://example.com ftp://example.com/ 
-Z, --parallel并行执行传输。

例子:
curl --parallel https://example.com -o file1 https://example.com -o file2
--pass <phrase>指定私钥密码。 

例子:
curl --pass secret --key file https://example.com 
--path-as-is防止 curl 合并/.//../排序。 

例子:
curl --path-as-is https://example.com/../../etc/passwd
--pinnedpubkey <hashes>指定 curl 使用的公钥。 

例子:
curl --pinnedpubkey keyfile https://example.com 
--post301防止 curl 在 301 重定向后将 POST 转换为 GET 请求。 

例子:
curl --post301 --location -d "data" https://example.com 
--post302防止 curl 在 302 重定向后将 POST 转换为 GET 请求。  

curl --post302 --location -d "data" https://example.com 
--post303防止 curl 在 303 重定向后将 POST 转换为 GET 请求。  

例子:
curl --post303 --location -d "data" https://example.com 
--preproxy [protocol://]host[:port]使用 SOCKS 代理作为预代理。 

例子:
curl --preproxy socks5://proxy.example -x http://http.example https://example.com 
-#, --progress-bar使用简单的进度条。

例子:
curl -# -O https://example.com 
--proto-default <protocol>指定 curl 应该对没有方案名称的 URL 使用哪个协议。 

例子:
curl --proto-default https ftp.example.com 
--proto-redir <protocols>指定 curl 应该在重定向时使用哪些协议。 

例子:
curl --proto-redir =http,https https://example.com 
--proto <protocols>指定 curl 应该使用哪些协议进行传输。  

例子:
curl --proto =http,https,sftp https://example.com 
--proxy-anyauthCurl 应该选择合适的身份验证方法。 

例子:
curl --proxy-anyauth --proxy-user user:passwd -x proxy https://example.com
--proxy-basic使用 HTTP Basic 与代理进行通信。 

例子:
curl --proxy-basic --proxy-user user:passwd -x proxy https://example.com 
--proxy-cacert <file>--cacert对于 HTTPS 代理。 

例子:
curl --proxy-cacert CA-file.txt -x https://proxy https://example.com 
--proxy-capath <dir>--capath对于 HTTPS 代理。 

例子:
curl --proxy-capath /local/directory -x https://proxy https://example.com
--proxy-cert-type <type>--cert-type对于 HTTPS 代理。 

例子:
curl --proxy-cert-type PEM --proxy-cert file -x https://proxy https://example.com
--proxy-cert <cert[:passwd]>-E,--cert用于 HTTPS 代理。 

例子:
curl --proxy-cert file -x https://proxy https://example.com 
--proxy-ciphers <list>--ciphers 对于 HTTPS 代理。 

curl --proxy-ciphers ECDHE-ECDSA-AES256-CCM8 -x https://proxy https://example.com 
--proxy-crlfile <file>--crlfile对于 HTTPS 代理。 

例子:
curl --proxy-crlfile rejects.txt -x https://proxy https://example.com
--proxy-digest将 HTTP Digest 身份验证与代理一起使用。 

例子:
curl --proxy-digest --proxy-user user:passwd -x proxy https://example.com 
--proxy-header <header/@file>-H,--header用于代理通信。 

例子:
curl --proxy-header "Host:" -x http://proxy https://example.com 
--proxy-insecure-k,--insecure用于 HTTPS 代理。 

例子:
curl --proxy-insecure -x https://proxy https://example.com 
--proxy-key-type <type>--key-type对于 HTTPS 代理。 

例子:
curl --proxy-key-type DER --proxy-key here -x https://proxy https://example.com 
--proxy-key <key>--key对于 HTTPS 代理。 

例子:
curl --proxy-key here -x https://proxy https://example.com 
--proxy-negotiate--negotiate用于代理通信。

例子:
curl --proxy-negotiate --proxy-user user:passwd -x proxy https://example.com
--proxy-ntlm将 HTTP NTLM 身份验证与代理一起使用。

例子:
curl --proxy-ntlm --proxy-user user:passwd -x http://proxy https://example.com
--proxy-pass <phrase>--pass对于 HTTPS 代理。 

例子:
curl --proxy-pass secret --proxy-key here -x https://proxy https://example.com 
--proxy-pinnedpubkey <hashes>指定用于代理验证的公钥。 

例子:
curl --proxy-pinnedpubkey keyfile https://example.com 
--proxy-service-name <name>指定代理通信的服务名称。 

例子:
curl --proxy-service-name "shrubbery" -x proxy https://example.com 
--proxy-ssl-allow-beast--ssl-allow-beast对于 HTTPS 代理。 

例子:
curl --proxy-ssl-allow-beast -x https://proxy https://example.com 
--proxy-ssl-auto-client-cert--ssl-auto-client-cert对于 HTTPS 代理。 

例子:
curl --proxy-ssl-auto-client-cert -x https://proxy https://example.com 
--proxy-tls13-ciphers <ciphersuite list>指定用于为代理协商 TLS 1.3 的密码套件列表。 

例子:
curl --proxy-tls13-ciphers TLS_AES_128_GCM_SHA256 -x proxy https://example.com
--proxy-tlsauthtype <type>--tlsauthtype对于 HTTPS 代理。 

例子:
curl --proxy-tlsauthtype SRP -x https://proxy https://example.com 
--proxy-tlspassword <string>--tlspassword对于 HTTPS 代理。

例子:
curl --proxy-tlspassword passwd -x https://proxy https://example.com 
--proxy-tlsuser <name>--tlsuser对于 HTTPS 代理。 

例子:
curl --proxy-tlsuser smith -x https://proxy https://example.com 
--proxy-tlsv1-1,--tlsv1用于 HTTPS 代理。 

例子:
curl --proxy-tlsv1 -x https://proxy https://example.com 
-U, --proxy-user <user:password>指定用于通过代理进行身份验证的用户名和密码。

例子:
curl --proxy-user name:pwd -x proxy https://example.com 
-x, --proxy [protocol://]host[:port]指定要使用的代理。

例子:
curl --proxy http://proxy.example https://example.com 
--proxy1.0 <host[:port]>指定要使用的 HTTP 1.0 代理。 

例子:
curl --proxy1.0 -x http://proxy https://example.com 
-p, --proxytunnel创建代理隧道。

例子:
curl --proxytunnel -x http://proxy https://example.com 
--pubkey <key>提供一个包含公钥的文件。 

例子:
curl --pubkey file.pub sftp://example.com/ 
-Q, --quote <command>向 FTP 或 SFTP 服务器发送命令,在传输之前执行。 

例子:
curl --quote "rm file" ftp://example.com/foo 
--random-file <file>指定包含随机数据的文件。此文件将用于播种随机引擎。 

例子:
curl --random-file rubbish https://example.com 
-r, --range <range>获取一个字节范围。 

例子:
curl --range 40-80 https://example.com 
--raw禁用 HTTP 内容解码并获取原始数据。 

例子:
curl --raw https://example.com 
-e, --referer <URL>发送引荐页面信息。 

例子:
curl --referer "https://test.example" https://example.com 
-J, --remote-header-name使用服务器指定的标头名称,而不是从 URL 获取它。

例子:
curl -OJ https://example.com/file 
--remote-name-all-O,--remote-name选项应用于所有 URL。

例子:
curl --remote-name-all ftp://example.com/file1 ftp://example.com/file2 
-O, --remote-name指定本地文件应具有下载的远程文件的名称。

例子:
curl -O https://example.com/filename 
-R, --remote-time指定本地文件应具有下载的远程文件的时间戳。

例子:
curl --remote-time -o foo https://example.com 
--request-target <path>指定备用目标路径。

例子:
curl --request-target "*" -X OPTIONS https://example.com 
-X, --request <command>指定与服务器通信的请求方法。

例子:
curl -X "DELETE" https://example.com 
--resolve <[+]host:port:addr[,addr]...>为主机/端口指定自定义地址。 

例子:
curl --resolve example.com:443:127.0.0.1 https://example.com 
--retry-all-errors强制重试所有错误。

例子:
curl --retry-all-errors https://example.com 
--retry-connrefused将 ECONNREFUSED 添加到符合--retry

例子:
curl --retry-connrefused --retry https://example.com 
--retry-delay <seconds>指定重试之间的时间量。 

例子:
curl --retry-delay 5 --retry https://example.com 
--retry-max-time <seconds>指定--retry尝试的最长时间。 

例子:
curl --retry-max-time 30 --retry 10 https://example.com 
--retry <num>指定 curl 遇到错误后的重试次数。 

例子:
curl --retry 7 https://example.com
--sasl-authzid <identity>为 SASL PLAIN 身份验证指定其他身份验证身份。 

例子:
curl --sasl-authzid zid imap://example.com/ 
--sasl-ir在 SASL 身份验证期间启用初始响应。

例子:
curl --sasl-ir imap://example.com/ 
--service-name <name>指定 SPNEGO 服务名称。 

例子:
curl --service-name sockd/server https://example.com 
-S, --show-error显示启用了-s,--silent选项的错误消息事件。 

例子:
curl --show-error --silent https://example.com 
-s, --silent开启静音模式。此选项使curl静音。

例子:
curl -s https://example.com 
--socks4 <host[:port]>指定 SOCKS4 代理。

例子:
curl --socks4 hostname:4096 https://example.com 
--socks4a <host[:port]>指定 SOCKS4a 代理。 

例子:
curl --socks4a hostname:4096 https://example.com 
--socks5-basic对 SOCKS5 代理使用基本身份验证方法(用户名/密码)。 

例子:
curl --socks5-basic --socks5 hostname:4096 https://example.com 
--socks5-gssapi-nec允许保护模式协商不受保护。

例子:
curl --socks5-gssapi-nec --socks5 hostname:4096 https://example.com 
--socks5-gssapi-service <name>更改袜子服务器的名称。

例子:
curl --socks5-gssapi-service sockd --socks5 hostname:4096 https://example.com 
--socks5-gssapi将 GSS-API 身份验证与 SOCKS5 代理结合使用。 

例子:
curl --socks5-gssapi --socks5 hostname:4096 https://example.com 
--socks5-hostname <host[:port]>指定要使用的 SOCKS5 代理。 

例子:
curl --socks5-hostname proxy.example:7000 https://example.com 
--socks5 <host[:port]>指定要使用的 SOCKS5 代理。主机名在本地解析。 

例子:
curl --socks5 proxy.example:7000 https://example.com 
-Y, --speed-limit <speed>设置下载速度的下限。

例子:
curl --speed-limit 300 --speed-time 10 https://example.com 
-y, --speed-time <seconds>设置限速测量的时间段。 

例子:
curl --speed-limit 300 --speed-time 10 https://example.com 
--ssl-allow-beast告诉 curl 忽略 SSL3 和 TLS1.0 协议中的 BEAST 安全漏洞。 

例子:
curl --ssl-allow-beast https://example.com 
--ssl-auto-client-cert自动获取和使用客户端证书。 

例子:
curl --ssl-auto-client-cert https://example.com 
--ssl-no-revoke不检查证书吊销。 

例子:
curl --ssl-no-revoke https://example.com 
--ssl-reqd需要 SSL/TLS。 

例子:
curl --ssl-reqd ftp://example.com 
--ssl-revoke-best-effort如果由于缺少分发点而失败,则忽略证书吊销检查。

例子:
curl --ssl-revoke-best-effort https://example.com 
--ssl尝试使用 SSL。 

例子:
curl --ssl pop3://example.com/ 
-2, --sslv2使用 SSLv2。由于 SSLv2 的安全问题,较新的 curl 版本会忽略此请求。

例子:
curl --sslv2 https://example.com 
-3, --sslv3使用 SSLv3。由于 SSLv3 的安全问题,较新的 curl 版本会忽略此请求。  

例子:
curl --sslv3 https://example.com 
--stderr <file>将 stderr 输出到文件。该-符号告诉 curl 将 stderr 输出到 stdout。 

例子:
curl --stderr output.txt https://example.com 
--styled-output为 HTTP 标头终端输出启用粗体。 

curl --styled-output -I https://example.com 
--suppress-connect-headers防止 curl 输出 CONNECT 标头。 

例子:
curl --suppress-connect-headers --include -x proxy https://example.com 
--tcp-fastopen启用 TCP 快速打开。

例子:
curl --tcp-fastopen https://example.com
--tcp-nodelay启用 TCP_NODELAY。 

例子:
curl --tcp-nodelay https://example.com 
-t, --telnet-option <opt=val>TTYPEXDISPLOCNEW_ENV选项传递给 telnet 协议。 

例子:
curl -t TTYPE=vt100 telnet://example.com/ 
--tftp-blksize <value>设置 TFTP BLKSIZE 的值。必须是大于 512 的值。 

示例:
curl --tftp-blksize 1024 tftp://example.com/file 
--tftp-no-options防止 curl 发送对 TFTP 选项的请求。

例子:
curl --tftp-no-options tftp://192.168.0.1/ 
-z, --time-cond <time>请求在特定日期和时间之后修改的文档。对于在该时间之前修改的文档,在日期表达式前加上破折号。
 
例子:
curl -z "Wed 01 Sep 2021 12:18:00" https://example.com 
--tls-max <VERSION>指定支持的最新 TLS 版本。

例子:
curl --tls-max 1.2 https://example.com 
--tls13-ciphers <ciphersuite list>指定用于协商 TLS 1.3 的密码套件列表  

示例:
curl --tls13-ciphers TLS_AES_128_GCM_SHA256 https://example.com 
--tlsauthtype <type>指定 TLS 身份验证类型。

例子:
curl --tlsauthtype SRP https://example.com 
--tlspassword <string>指定 TLS 密码。 

例子:
curl --tlspassword pwd --tlsuser user https://example.com 
--tlsuser <name>指定 TLS 用户名。 

例子:
curl --tlspassword pwd --tlsuser user https://example.com 
--tlsv1.0告诉 curl 使用 TLS1.0 或更新版本。 

例子:
curl --tlsv1.0 https://example.com 
--tlsv1.1告诉 curl 使用 TLS1.1 或更新版本。  

例子:
curl --tlsv1.1 https://example.com 
--tlsv1.2告诉 curl 使用 TLS1.2 或更新版本。  

例子:
curl --tlsv1.2 https://example.com 
--tlsv1.3告诉 curl 使用 TLS1.3 或更新版本。  

例子:
curl --tlsv1.3 https://example.com 
-1, --tlsv1指定 curl 应至少使用 1.x 版本的 TLS。

例子:
curl --tlsv1 https://example.com 
--tr-encoding请求压缩的传输编码响应。

例子:
curl --tr-encoding https://example.com 
--trace-ascii <file>启用到文件的完整跟踪转储。消除十六进制部分并仅显示 ASCII。

例子:
curl --trace-ascii log.txt https://example.com 
--trace-time需要在每个跟踪或详细行上添加时间戳。 

例子:
curl --trace-time --trace-ascii output https://example.com 
--trace <file>启用到文件的完整跟踪转储。  

例子:
curl --trace log.txt https://example.com 
--unix-socket <path>指定 Unix 套接字路径。 

例子:
curl --unix-socket socket-path https://example.com 
-T, --upload-file <file>将文件上传到 URL。 

Linux curl命令用法示例:
curl -T "img[1-1000].png" ftp://ftp.example.com/ 
--url <url>提供要获取的 URL。 

例子:
curl --url https://example.com 
-B, --use-ascii启用 ASCII 传输。 

例子:
curl -B ftp://example.com/README 
-A, --user-agent <name>指定用户代理名称。 

例子:
curl -A "Agent 007" https://example.com 
-u, --user <user:password>提供用于身份验证的用户名和密码。 

例子:
curl -u user:secret https://example.com 
-v, --verbose告诉 curl 冗长。 

例子:
curl --verbose https://example.com 
-V, --version查看已安装的 curl 和 libcurl 版本。

例子:
curl --version 
-w, --write-out <format>告诉 curl 在标准输出上显示有关已完成传输的信息。 

例子:
curl -w '%{http_code}\n' https://example.com 
--xattr将文件元数据存储在文件属性中。

例子:
curl --xattr -o storage https://example.com  

有关选项的全面说明,请curl --manual在终端中执行命令。

Linux curl命令使用教程结论

Linux curl命令如何使用?阅读本教程后,你应该知道如何使用 curl 命令及其众多选项。要了解有关 curl 可以做什么的更多信息,请阅读如何使用 curl 设置或更改用户代理。

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: