Linux curl 命令

2017-09-19|Categories: External cmd, Linux|



curl -LO

  • -L, --location:访问某些URL时会被服务器重定向,指定-L选项之后,curl会继续访问重定向之后的URL。
    • -I, --head选项可以查询URL是否会被重定向,这个选项会输出HTTP响应头,其中的Location就是重定向之后的URL。
  • -O, --remote-name:提取URL最后一部分(最后一个/之后的字符)作为下载文件的名称,在这里就是mirror


curl -L -o php-7.1.9.tar.gz

有没有办法让下载的文件直接使用它在服务器上的名称呢?有,但有条件:-J, --remote-header-name可以使用服务器指定的Content-Disposition文件名,如果服务器没有指定或指定的格式不正确,-J选项就无能为力,例如:

# 成功,保存为`molokai.vim`
curl -JLO

# 失败,保存为`mirror`
curl -JLO


# `wget --content-disposition`
# 成功,保存为`php-7.1.9.tar.gz`
wget --content-disposition
# 成功,保存为`molokai.vim`
wget --content-disposition

# `wget --trust-server-names`
# 成功,保存为`php-7.1.9.tar.gz`
wget --trust-server-names
# 失败,保存为`download_script.php?src_id=9750`
wget --trust-server-names

需要注意的是,curl -Jwget --content-disposition --trust-server-names都有安全风险,尤其是在Windows系统上:恶意服务器可以指定*.dll之类可被自动执行的文件名,使用时务必慎重。



curl dict://

To help you remember, d: stands for DEFINE.

For example, to look up the word "bash", (all output in this article are greatly abbreviated for clarity)

curl dict://

151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, n.
1. a forceful blow, especially one that does damage to its
2. a elaborate or lively social gathering or party.

The web site supports 77 dictionaries. To list them:

curl dict://

So, if you want to know the computer meaning of "bash", specify foldoc "The Free On-line Dictionary of Computing" like this:

curl dict://

151 "bash" foldoc "The Free On-line Dictionary of Computing (27 SEP 03)"
Bourne Again SHell. {GNU}'s {command interpreter} for {Unix}.
Bash is a {Posix}-compatible {shell} with full {Bourne shell}
syntax, and some {C shell} commands built in. The Bourne
Again Shell supports {Emacs}-style command-line editing, job
control, functions, and on-line help. Written by Brian Fox of

To display results from all libraries, do this:

curl dict://*

Fuzzy matching is also possible. Replace the "d" or Define command with "m" which stands for MATCH.

curl dict://

With the match command, you can also specify the strategy such as exact, prefix, suffix, or even soundex.

curl dict://

gcide "Bash"
gcide "Bashed"
gcide "Bashful"
gcide "bashful Billy"

To list all supported strategies:

curl dict://

查看HTTP请求头 2018-01-24

HTTP响应头(Response header)可以用-I选项查看,而请求头(Request header)可以用-v选项查看。

  • -s, --silent:安静模式,不显示进度条或错误信息。
  • > /dev/null:只显示-v选项的输出,避免重复。


$ curl -Ivs > /dev/null
* Rebuilt URL to:
*   Trying
* Connected to ( port 6152 (#0)
> Host:
> User-Agent: curl/7.54.0
> Accept: */*
> Referer:
> Proxy-Connection: Keep-Alive
< HTTP/1.1 200 OK
< Date: Wed, 24 Jan 2018 11:17:28 GMT
< Server: Apache
< Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
< ETag: "51-47cf7e6ee8400"
< Accept-Ranges: bytes
< Content-Length: 81
< Cache-Control: max-age=86400
< Expires: Thu, 25 Jan 2018 11:17:28 GMT
< Connection: Keep-Alive
< Content-Type: text/html
* Connection #0 to host left intact

查看本机的公网IP 2018-02-21



# `eth0`是CentOS 6默认的网卡名称,
# CentOS 7默认的网卡名称是`ens33`
ifconfig eth0 | grep netmask | awk '{print $2}'

忽略系统代理设置 2018-04-06

某些时候测试走代理会报错,例如测试局域网地址,此时可以用--noproxy '*'忽略所有系统代理设置:

curl --noproxy '*' -vs >/dev/null

Leave A Comment