工作中查看Linux命令的帮助文档可以有两种方式,以curl命令为例:
curl --help
man curl
curl
命令可以对URL地址发起请求,有-s
、 -I
、 -v
等等命令
- 以-s、-I命令为例,先来看看–help查询到的帮助信息:
-s --silent Silent mode (don't output anything)
-I, --head Show document info only
翻译成中文大概意思就是
-s --silent 静默模式,不输出任何东西
-I --head 仅显示文档信息
信息查到了,第一次看其实还是有点懵,比如说-s
命令,用
curl -s https://testerhome.com | grep href
访问testerhome社区,说好的不输出任何东西,但是整个访问返回的网页信息都输出了啊:
qinzhendeMacBook-Pro:~ qinzhen$ curl -s https://testerhome.com | grep href
<link rel="icon" href="/assets/favicon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="apple-touch-icon-precomposed" href="/assets/ios-icon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="shortcut icon" href="/assets/big_logo-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="apple-touch-icon" href="/assets/favicon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png">
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
<link rel="alternate" type="application/rss+xml" title="订阅最新帖" href="https://testerhome.com/topics/feed"/>
<link rel="stylesheet" media="screen" href="/assets/front-287044a6285b3034b763fd338d0385271dbca75872db865d6d714ba9b2628f34.css" data-turbolinks-track="reload" />
<a href="https://testerhome.com/topics/19664" type="button" class="btn btn-info">查看详情</a>
......#后面的内容省略
- 这里再来看
man
命令查询到的-s
、-I
的文档解释
-s, --slient
Silent or quiet mode. Don't show progress meter or error messages.
-I, --head
(HTTP FTP FILE) Fetch the headers only!
HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document.
When used on an FTP or FILE file, curl displays the file size and last modification time only.
翻译成中文的意思大概是
-s, --slient 无声或安静模式,不显示进度表或错误消息
-I, --head 当对应HTTP服务时只展示头信息,当使用FTP or FILE文件时,只展示文件大小和上一次的修改时间
-v, --verbose 显示更多的细节
这里的解释就比上一步中的清晰多了,分别运行
curl https://testerhome.com | grep href
curl -s https://testerhome.com | grep href
对比如下:
qinzhendeMacBook-Pro:~ qinzhen$ curl https://testerhome.com | grep href
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 <link rel="icon" href="/assets/favicon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="apple-touch-icon-precomposed" href="/assets/ios-icon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="shortcut icon" href="/assets/big_logo-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="apple-touch-icon" href="/assets/favicon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png">
......#后面的内容省略
qinzhendeMacBook-Pro:~ qinzhen$ curl -s https://testerhome.com | grep href
<link rel="icon" href="/assets/favicon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="apple-touch-icon-precomposed" href="/assets/ios-icon-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
<link rel="shortcut icon" href="/assets/big_logo-cd32144f74c18746f3dce33e1040e7dfe4c07c8e611e37f3868b1c16b5095da3.png"/>
......#后面的内容省略
这里对比发现很明显了,用-s
命令后的的展示结果去掉了最上方的进度表信息
顺便执行下curl -s -I https://testerhome.com
命令看下输出结果:
qinzhendeMacBook-Pro:~ qinzhen$ curl -s -I https://testerhome.com
HTTP/1.1 200 OK
Server: nginx/1.10.2
Date: Sat, 31 Aug 2019 04:55:46 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
Referrer-Policy: strict-origin-when-cross-origin
ETag: W/"81e569bf92598df50c5397f7080b6854"
Cache-Control: max-age=0, private, must-revalidate
Content-Security-Policy: ;
Set-Cookie: user_id=bnVsbA%3D%3D--69ec4bae7d601a6036395dbe51d1d2ffcd6fa592; path=/; secure
Set-Cookie: _homeland_session=DMhTdNrEmeYU69HrTOWfG5%2Fe40T8hiZ8yLESeIT4MOa84IHLg7W34jZPVJaP3YpK1L9nDPtI1xTRKig2T0tXmkGYDle5euScakeemuCy3PLcd2uiz7u7cuc%2BZ55mFxES8LD2R0IqMRk%2Fmi5ZZGBdgdszRoNRun5vUfC9UdiKz7F5FVfIEDXfdZ5sPnljVD70Z9nf01O4JCEkBJ6wyNrLtBBjPCyCu%2FGGQqfYDSza95Mp3sBpM6YtJ7g2KNoEU5Mjj70sfe46i1WuHMpS6g2HuI%2B1usda5J1Q8w%3D%3D--7H8PB2Bo%2BVwL2SaJ--vzZKAk7OnSDCfdvd0Ej9Og%3D%3D; path=/; expires=Fri, 29 Nov 2019 04:55:46 -0000; secure; HttpOnly
X-Request-Id: 3d577fc5-e77c-42b1-9b2c-ed9791924bf6
X-Runtime: 0.089027
Strict-Transport-Security: max-age=15552000; includeSubDomains
这里也可以很明显的看到,-I
命令获取的就是响应头的信息
总结
通过上述实践验证可得到一个结论:
man比–help查询到的帮助文档信息更详细
小插曲~
man其实是manual,手册的意思;不知道有没有人和我一样,第一次看到的时候想到了男人(man),然后我就想:难道说因为男人必须要牛X?所以查询到的信息也更多更详细?然后就以男人作为命令了?哈哈哈哈~ 这里我都把自己给逗乐了,不过也因此记住了它们两者的区别了~