linux curl命令参数有哪些及怎么使用

linux curl是一个利用url规则在命令行下工作的文件传输工具。它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称url为下载工具。

  一,curl命令参数

  -a/--append 上传文件时,附加到目标文件

  -a/--user-agent <string> 设置用户代理发送给服务器

  - anyauth 可以使用“任何”身份验证方法

  -b/--cookie <name=string/file> cookie字符串或文件读取位置

  - basic 使用http基本验证

  -b/--use-ascii 使用ascii /文本传输

  -c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中

  -c/--continue-at <offset> 断点续转

  -d/--data <data> http post方式传送数据

  --data-ascii <data> 以ascii的方式post数据

  --data-binary <data> 以二进制的方式post数据

  --negotiate 使用http身份验证

  --digest 使用数字身份验证

  --disable-eprt 禁止使用eprt或lprt

  --disable-epsv 禁止使用epsv

  -d/--dump-header <file> 把header信息写入到该文件中

  --egd-file <file> 为随机数据(ssl)设置egd socket路径

  --tcp-nodelay 使用tcp_nodelay选项

  -e/--referer 来源网址

  -e/--cert <cert[:passwd]> 客户端证书文件和密码 (ssl)

  --cert-type <type> 证书文件类型 (der/pem/eng) (ssl)

  --key <key> 私钥文件名 (ssl)

  --key-type <type> 私钥文件类型 (der/pem/eng) (ssl)

  --pass <pass> 私钥密码 (ssl)

  --engine <eng> 加密引擎使用 (ssl). "--engine list" for list

  --cacert <file> ca证书 (ssl)

  --capath <directory> ca目录 (made using c_rehash) to verify peer against (ssl)

  --ciphers <list> ssl密码

  --compressed 要求返回是压缩的形势 (using deflate or gzip)

  --connect-timeout <seconds> 设置最大请求时间

  --create-dirs 建立本地目录的目录层次结构

  --crlf 上传是把lf转变成crlf

  -f/--fail 连接失败时不显示http错误

  --ftp-create-dirs 如果远程目录不存在,创建远程目录

  --ftp-method [multicwd/nocwd/singlecwd] 控制cwd的使用

  --ftp-pasv 使用 pasv/epsv 代替端口

  --ftp-skip-pasv-ip 使用pasv的时候,忽略该ip地址

  --ftp-ssl 尝试用 ssl/tls 来进行ftp数据传输

  --ftp-ssl-reqd 要求用 ssl/tls 来进行ftp数据传输

  -f/--form <name=content> 模拟http表单提交数据

  -form-string <name=string> 模拟http表单提交数据

  -g/--globoff 禁用网址序列和范围使用{}和[]

  -g/--get 以get的方式来发送数据

  -h/--help 帮助

  -h/--header <line>自定义头信息传递给服务器

  --ignore-content-length 忽略的http头信息的长度

  -i/--include 输出时包括protocol头信息

  -i/--head 只显示文档信息

  从文件中读取-j/--junk-session-cookies忽略会话cookie

  - 界面<interface>指定网络接口/地址使用

  - krb4 <级别>启用与指定的安全级别krb4

  -j/--junk-session-cookies 读取文件进忽略session cookie

  --interface <interface> 使用指定网络接口/地址

  --krb4 <level> 使用指定安全级别的krb4

  -k/--insecure 允许不使用证书到ssl站点

  -k/--config 指定的配置文件读取

  -l/--list-only 列出ftp目录下的文件名称

  --limit-rate <rate> 设置传输速度

  --local-port<num> 强制使用本地端口号

  -m/--max-time <seconds> 设置最大传输时间

  --max-redirs <num> 设置最大读取的目录数

  --max-filesize <bytes> 设置最大下载的文件总量

  -m/--manual 显示全手动

  -n/--netrc 从netrc文件中读取用户名和密码

  --netrc-optional 使用 .netrc 或者 url来覆盖-n

  --ntlm 使用 http ntlm 身份验证

  -n/--no-buffer 禁用缓冲输出

  -o/--output 把输出写到该文件中

  -o/--remote-name 把输出写到该文件中,保留远程文件的文件名

  -p/--proxytunnel 使用http代理

  --proxy-anyauth 选择任一代理身份验证方法

  --proxy-basic 在代理上使用基本身份验证

  --proxy-digest 在代理上使用数字身份验证

  --proxy-ntlm 在代理上使用ntlm身份验证

  -p/--ftp-port <address> 使用端口地址,而不是使用pasv

  -q/--quote <cmd>文件传输前,发送命令到服务器

  -r/--range <range>检索来自http/1.1或ftp服务器字节范围

  --range-file 读取(ssl)的随机文件

  -r/--remote-time 在本地生成文件时,保留远程文件时间

  --retry <num> 传输出现问题时,重试的次数

  --retry-delay <seconds> 传输出现问题时,设置重试间隔时间

  --retry-max-time <seconds> 传输出现问题时,设置最大重试时间

  -s/--silent静音模式。不输出任何东西

  -s/--show-error 显示错误

  --socks4 <host[:port]> 用socks4代理给定主机和端口

  --socks5 <host[:port]> 用socks5代理给定主机和端口

  --stderr <file>
-t/--telnet-option <opt=val> telnet选项设置

  --trace <file> 对指定文件进行debug

  --trace-ascii <file> like --跟踪但没有hex输出

  --trace-time 跟踪/详细输出时,添加时间戳

  -t/--upload-file <file> 上传文件

  --url <url> spet url to work with

  -u/--user <user[:password]>设置服务器的用户和密码

  -u/--proxy-user <user[:password]>设置代理用户名和密码

  -v/--verbose

  -v/--version 显示版本信息

  -w/--write-out [format]什么输出完成后

  -x/--proxy <host[:port]>在给定的端口上使用http代理

  -x/--request <command>指定什么命令

  -y/--speed-time 放弃限速所要的时间。默认为30

  -y/--speed-limit 停止传输速度的限制,速度时间'秒

  -z/--time-cond 传送时间设置

  -0/--http1.0 使用http 1.0

  -1/--tlsv1 使用tlsv1(ssl)

  -2/--sslv2 使用sslv2的(ssl)

  -3/--sslv3 使用的sslv3(ssl)

  --3p-quote like -q for the source url for 3rd party transfer

  --3p-url 使用url,进行第三方传送

  --3p-user 使用用户名和密码,进行第三方传送

  -4/--ipv4 使用ip4

  -6/--ipv6 使用ip6

  -#/--progress-bar 用进度条显示当前的传送状态

  -a/--append 上传文件时,附加到目标文件

  -a/--user-agent <string> 设置用户代理发送给服务器

  - anyauth 可以使用“任何”身份验证方法

  -b/--cookie <name=string/file> cookie字符串或文件读取位置

  - basic 使用http基本验证

  -b/--use-ascii 使用ascii /文本传输

  -c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中

  -c/--continue-at <offset> 断点续转

  -d/--data <data> http post方式传送数据

  --data-ascii <data> 以ascii的方式post数据

  --data-binary <data> 以二进制的方式post数据

  --negotiate 使用http身份验证

  --digest 使用数字身份验证

  --disable-eprt 禁止使用eprt或lprt

  --disable-epsv 禁止使用epsv

  -d/--dump-header <file> 把header信息写入到该文件中

  --egd-file <file> 为随机数据(ssl)设置egd socket路径

  --tcp-nodelay 使用tcp_nodelay选项

  -e/--referer 来源网址

  -e/--cert <cert[:passwd]> 客户端证书文件和密码 (ssl)

  --cert-type <type> 证书文件类型 (der/pem/eng) (ssl)

  --key <key> 私钥文件名 (ssl)

  --key-type <type> 私钥文件类型 (der/pem/eng) (ssl)

  --pass <pass> 私钥密码 (ssl)

  --engine <eng> 加密引擎使用 (ssl). "--engine list" for list

  --cacert <file> ca证书 (ssl)

  --capath <directory> ca目录 (made using c_rehash) to verify peer against (ssl)

  --ciphers <list> ssl密码

  --compressed 要求返回是压缩的形势 (using deflate or gzip)

  --connect-timeout <seconds> 设置最大请求时间

  --create-dirs 建立本地目录的目录层次结构

  --crlf 上传是把lf转变成crlf

  -f/--fail 连接失败时不显示http错误

  --ftp-create-dirs 如果远程目录不存在,创建远程目录

  --ftp-method [multicwd/nocwd/singlecwd] 控制cwd的使用

  --ftp-pasv 使用 pasv/epsv 代替端口

  --ftp-skip-pasv-ip 使用pasv的时候,忽略该ip地址

  --ftp-ssl 尝试用 ssl/tls 来进行ftp数据传输

  --ftp-ssl-reqd 要求用 ssl/tls 来进行ftp数据传输

  -f/--form <name=content> 模拟http表单提交数据

  -form-string <name=string> 模拟http表单提交数据

  -g/--globoff 禁用网址序列和范围使用{}和[]

  -g/--get 以get的方式来发送数据

  -h/--help 帮助

  -h/--header <line>自定义头信息传递给服务器

  --ignore-content-length 忽略的http头信息的长度

  -i/--include 输出时包括protocol头信息

  -i/--head 只显示文档信息

  从文件中读取-j/--junk-session-cookies忽略会话cookie

  - 界面<interface>指定网络接口/地址使用

  - krb4 <级别>启用与指定的安全级别krb4

  -j/--junk-session-cookies 读取文件进忽略session cookie

  --interface <interface> 使用指定网络接口/地址

  --krb4 <level> 使用指定安全级别的krb4

  -k/--insecure 允许不使用证书到ssl站点

  -k/--config 指定的配置文件读取

  -l/--list-only 列出ftp目录下的文件名称

  --limit-rate <rate> 设置传输速度

  --local-port<num> 强制使用本地端口号

  -m/--max-time <seconds> 设置最大传输时间

  --max-redirs <num> 设置最大读取的目录数

  --max-filesize <bytes> 设置最大下载的文件总量
-m/--manual 显示全手动

  -n/--netrc 从netrc文件中读取用户名和密码

  --netrc-optional 使用 .netrc 或者 url来覆盖-n

  --ntlm 使用 http ntlm 身份验证

  -n/--no-buffer 禁用缓冲输出

  -o/--output 把输出写到该文件中

  -o/--remote-name 把输出写到该文件中,保留远程文件的文件名

  -p/--proxytunnel 使用http代理

  --proxy-anyauth 选择任一代理身份验证方法

  --proxy-basic 在代理上使用基本身份验证

  --proxy-digest 在代理上使用数字身份验证

  --proxy-ntlm 在代理上使用ntlm身份验证

  -p/--ftp-port <address> 使用端口地址,而不是使用pasv

  -q/--quote <cmd>文件传输前,发送命令到服务器

  -r/--range <range>检索来自http/1.1或ftp服务器字节范围

  --range-file 读取(ssl)的随机文件

  -r/--remote-time 在本地生成文件时,保留远程文件时间

  --retry <num> 传输出现问题时,重试的次数

  --retry-delay <seconds> 传输出现问题时,设置重试间隔时间

  --retry-max-time <seconds> 传输出现问题时,设置最大重试时间

  -s/--silent静音模式。不输出任何东西

  -s/--show-error 显示错误

  --socks4 <host[:port]> 用socks4代理给定主机和端口

  --socks5 <host[:port]> 用socks5代理给定主机和端口

  --stderr <file>

  -t/--telnet-option <opt=val> telnet选项设置

  --trace <file> 对指定文件进行debug

  --trace-ascii <file> like --跟踪但没有hex输出

  --trace-time 跟踪/详细输出时,添加时间戳

  -t/--upload-file <file> 上传文件

  --url <url> spet url to work with

  -u/--user <user[:password]>设置服务器的用户和密码

  -u/--proxy-user <user[:password]>设置代理用户名和密码

  -v/--verbose

  -v/--version 显示版本信息

  -w/--write-out [format]什么输出完成后

  -x/--proxy <host[:port]>在给定的端口上使用http代理

  -x/--request <command>指定什么命令

  -y/--speed-time 放弃限速所要的时间。默认为30

  -y/--speed-limit 停止传输速度的限制,速度时间'秒

  -z/--time-cond 传送时间设置

  -0/--http1.0 使用http 1.0

  -1/--tlsv1 使用tlsv1(ssl)

  -2/--sslv2 使用sslv2的(ssl)

  -3/--sslv3 使用的sslv3(ssl)

  --3p-quote like -q for the source url for 3rd party transfer

  --3p-url 使用url,进行第三方传送

  --3p-user 使用用户名和密码,进行第三方传送

  -4/--ipv4 使用ip4

  -6/--ipv6 使用ip6

  -#/--progress-bar 用进度条显示当前的传送状态

  二,常用curl实例

  1,抓取页面内容到一个文件中

  [root@krlcgcms01 mytest]# curl -o home.html

  [root@krlcgcms01 mytest]# curl -o home.html

  2,用-o(大写的),后面的url要具体到某个文件,不然抓不下来。我们还可以用正则来抓取东西

  [root@krlcgcms01 mytest]# curl -o

  [root@krlcgcms01 mytest]# curl -o

  3,模拟表单信息,模拟登录,保存cookie信息

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -f log=aaaa -f pwd=******

  [root@krlcgcms01 mytest]# curl -c ./cookie_c.txt -f log=aaaa -f pwd=******

  4,模拟表单信息,模拟登录,保存头信息

  [root@krlcgcms01 mytest]# curl -d ./cookie_d.txt -f log=aaaa -f pwd=******

  [root@krlcgcms01 mytest]# curl -d ./cookie_d.txt -f log=aaaa -f pwd=******

  -c(小写)产生的cookie和-d里面的cookie是不一样的。

  5,使用cookie文件

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt

  [root@krlcgcms01 mytest]# curl -b ./cookie_c.txt

  6,断点续传,-c(大写的)

  [root@krlcgcms01 mytest]# curl -c -o

  7,传送数据,最好用登录页面测试,因为你传值过去后,curl回抓数据,你可以看到你传值有没有成功

  [root@krlcgcms01 mytest]# curl -d log=aaaa

  [root@krlcgcms01 mytest]# curl -d log=aaaa

  8,显示抓取错误,下面这个例子,很清楚的表明了。

  [root@krlcgcms01 mytest]# curl -f

  curl: (22) the requested url returned error: 404

  [root@krlcgcms01 mytest]# curl

  <html><head><title>404,not found</title>

  。。。。。。。。。。。。

  [root@krlcgcms01 mytest]# curl -f

  curl: (22) the requested url returned error: 404

  [root@krlcgcms01 mytest]# curl

  <html><head><title>404,not found</title>

  。。。。。。。。。。。。

  9,伪造来源地址,有的网站会判断,请求来源地址。

  [root@krlcgcms01 mytest]# curl -e

  [root@krlcgcms01 mytest]# curl -e

  10,当我们经常用curl去搞人家东西的时候,人家会把你的ip给屏蔽掉的,这个时候,我们可以用代理

  [root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html

  [root@krlcgcms01 mytest]# curl -x 24.10.28.84:32779 -o home.html
11,比较大的东西,我们可以分段下载

  [root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 101 100 101 0 0 105 0 --:--:-- --:--:-- --:--:-- 0

  [root@krlcgcms01 mytest]# curl -r 100-200 -o img.part2 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 101 100 101 0 0 57 0 0:00:01 0:00:01 --:--:-- 0

  [root@krlcgcms01 mytest]# curl -r 200- -o img.part3 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 104k 100 104k 0 0 52793 0 0:00:02 0:00:02 --:--:-- 88961

  [root@krlcgcms01 mytest]# ls |grep part | xargs du -sh

  4.0k one.part1

  112k three.part3

  4.0k two.part2

  [root@krlcgcms01 mytest]# curl -r 0-100 -o img.part1 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 101 100 101 0 0 105 0 --:--:-- --:--:-- --:--:-- 0

  [root@krlcgcms01 mytest]# curl -r 100-200 -o img.part2 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 101 100 101 0 0 57 0 0:00:01 0:00:01 --:--:-- 0

  [root@krlcgcms01 mytest]# curl -r 200- -o img.part3 -

  content/uploads/2010/09/compare_varnish.jpg

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  100 104k 100 104k 0 0 52793 0 0:00:02 0:00:02 --:--:-- 88961

  [root@krlcgcms01 mytest]# ls |grep part | xargs du -sh

  4.0k one.part1

  112k three.part3

  4.0k two.part2

  用的时候,把他们cat一下就ok了,cat img.part* >img.jpg

  12,不会显示下载进度信息

  [root@krlcgcms01 mytest]# curl -s -o aaa.jpg

  13,显示下载进度条

  [root@krlcgcms01 mytest]# curl -# -o

  ######################################################################## 100.0%

  14,通过ftp下载文件

  [zhangy@blackghost ~]$ curl -u 用户名:密码 -o

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  101 1934 101 1934 0 0 3184 0 --:--:-- --:--:-- --:--:-- 7136

  [zhangy@blackghost ~]$ curl -u 用户名:密码 -o

  % total % received % xferd average speed time time time current

  dload upload total spent left speed

  101 1934 101 1934 0 0 3184 0 --:--:-- --:--:-- --:--:-- 7136

  或者用下面的方式

  [zhangy@blackghost ~]$ curl -o ftp://用户名:密码@ip:port/demo/curtain/bbstudy_files/style.css

  [zhangy@blackghost ~]$ curl -o ftp://用户名:密码@ip:port/demo/curtain/bbstudy_files/style.css

  15,通过ftp上传

  [zhangy@blackghost ~]$ curl -t test.sql ftp://用户名:密码@ip:port/demo/curtain/bbstudy_files/

  [zhangy@blackghost ~]$ curl -t test.sql ftp://用户名:密码@ip:port/demo/curtain/bbstudy_files/

以上就是linux curl命令参数有哪些及怎么使用的详细内容,更多请关注主机测评网其它相关文章!

阅读剩余
THE END