Linux curl 命令详解( 七 )


--retry-delay <seconds>传输出现问题时,设置重试间隔时间 。将此延迟设置为零将使curl使用默认的延迟时间 。
--retry-max-time <seconds>传输出现问题时,设置最大重试时间 。将此选项设置为0则不超时重试 。
 
常用选项六-s, --silent静默或静音模式 。不显示进度表/条或错误消息 。
示例
1 [root@iZ28xbsfvc4Z 20190713]# curl https://www.baidu.com | head -n1# 默认有进度表2% Total% Received % XferdAverage SpeedTimeTimeTimeCurrent3DloadUploadTotalSpentLeftSpeed4 1002443100244300133460 --:--:-- --:--:-- --:--:-- 133495 <!DOCTYPE html>6 [root@iZ28xbsfvc4Z 20190713]# curl -s https://www.baidu.com | head -n17 <!DOCTYPE html> 
-S, --show-error当与 -s 一起使用时,如果curl失败,curl将显示一条错误消息 。
1 [root@iZ28xbsfvc4Z 20190713]# curl -s https://140.205.16.113/ 2 [root@iZ28xbsfvc4Z 20190713]# 3 [root@iZ28xbsfvc4Z 20190713]# curl -sS https://140.205.16.113/ 4 curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate. 
--stderr <file>将错误信息重定向到一个文件 。如果文件名是普通的 ‘-‘,则将其写入stdout 。
如果多次使用此选项,则将使用最后一个选项 。
1 [root@iZ28xbsfvc4Z 20190713]# curl --stderr err.info https://140.205.16.113/ 2 [root@iZ28xbsfvc4Z 20190713]# ll3 total 924 -rw-r--r-- 1 root root116 Jul 13 10:19 err.info5 [root@iZ28xbsfvc4Z 20190713]# cat err.info 6 curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate. 
-T, --upload-file <file>这将指定的本地文件传输到远程URL 。如果指定的URL中没有文件部分,Curl将附加本地文件名 。
注意:必须在最后一个目录上使用尾随 / 来真正证明Curl没有文件名,否则Curl会认为您的最后一个目录名是要使用的远程文件名 。这很可能导致上传操作失败 。如果在HTTP(S)服务器上使用此命令,则将使用PUT命令 。
同时也支持多个文件上传,如下:
curl -T "{file1,file2}" http://www.uploadtothissite.com或则curl -T "img[1-1000].png" ftp://ftp.picturemania.com/upload/ 
--trace <file>对指定文件进行debug 。包括所有传入和传出数据 。
此选项会覆盖之前使用的 -v、--verbose或 --trace-ascii 。
如果多次使用此选项,则将使用最后一个选项 。
curl --trace trace.info https://www.baidu.com 
--trace-ascii <file>对指定文件进行debug 。包括所有传入和传出数据 。
这非常类似于 --trace,但是省略了十六进制部分,只显示转储的ASCII部分 。使它输出更小,对于我们来说可能更容易阅读 。
此选项会覆盖之前使用的 -v、--verbose或 --trace 。
如果多次使用此选项,则将使用最后一个选项 。
curl --trace-ascii trace2.info https://www.baidu.com 
--trace-time为curl显示的每个跟踪或冗长的行添加时间戳 。
curl --trace-ascii trace3.info --trace-time https://www.baidu.com 
-v, --verbose显示详细操作信息 。主要用于调试 。
以 > 开头的行表示curl发送的”header data”;< 表示curl接收到的通常情况下隐藏的”header data”;而以 * 开头的行表示curl提供的附加信息 。
1 [root@iZ28xbsfvc4Z 20190712]# curl -v https://www.baidu.com 2 * About to connect() to www.baidu.com port 443 (#0) 3 *Trying 180.101.49.12... 4 * Connected to www.baidu.com (180.101.49.12) port 443 (#0) 5 * Initializing NSS with certpath: sql:/etc/pki/nssdb 6 *CAfile: /etc/pki/tls/certs/ca-bundle.crt 7CApath: none 8 * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 9 * Server certificate:10 *subject: CN=baidu.com,O="Beijing Baidu Netcom Science Technology Co., Ltd",OU=service operation department,L=beijing,ST=beijing,C=CN11 *start date: May 09 01:22:02 2019 GMT12 *expire date: Jun 25 05:31:02 2020 GMT13 *common name: baidu.com14 *issuer: CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE15 > GET / HTTP/1.116 > User-Agent: curl/7.29.017 > Host: www.baidu.com18 > Accept: */*19 > 20 < HTTP/1.1 200 OK21 < Accept-Ranges: bytes22 < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform23 < Connection: Keep-Alive24 < Content-Length: 244325 < Content-Type: text/html26 < Date: Fri, 12 Jul 2019 08:26:23 GMT27 < Etag: "588603eb-98b"28 < Last-Modified: Mon, 23 Jan 2017 13:23:55 GMT29 < Pragma: no-cache30 < Server: bfe/1.0.8.1831 < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/32 < 33 <!DOCTYPE html>34 ………………# curl 网页的具体信息


推荐阅读