Linux curl使用简单介绍

简介: Curl是Linux下一个很强大的http命令行工具,其功能十分强大。 1)读取网页 $ curl linuxidc.

Curl是Linux下一个很强大的http命令行工具,其功能十分强大。

1)读取网页

$ curl linuxidc.com">http://www.linuxidc.com

2)保存网页

$ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com

3)使用的proxy服务器及其端口:-x

$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4)使用cookie来记录session信息

$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com这个option: -D 是把http的response里面的cookie信息存到一个特别的文件中去,这样,当页面被存到page.html的同时,cookie信息也被存到了cookie0001.txt里面了5)那么,下一次访问的时候,如何继续使用上次留下的cookie信息呢?

使用option来把上次的cookie信息追加到http request里面去:-b

$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

6)浏览器信息

$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

7)referer

$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com这样就可以骗对方的服务器,你是从mail.linuxidc.com点击某个链接过来的

8)下载文件

$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG $ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG -O 可以按照服务器上的文件名,自动存在本地$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

9)批量下载

$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG这样产生的下载,就是~zzh/001.JPG ~zzh/002.JPG

……

~zzh/201.JPG ~nick/001.JPG ~nick/002.JPG

……

~nick/201.JPG

$自定义文件名的下载

curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG这样,自定义出来下载下来的文件名,就变成了这样:原来: ~zzh/001.JPG —-> 下载后: 001-zzh.JPG 原来: ~nick/001.JPG —-> 下载后: 001-nick.JPG

这样一来就不怕文件重名啦

9)断点续传

$ curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG分块下载,我们使用这个option就可以了: -r

举例说明

比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 要下载(赵老师的电话朗诵 :D )我们就可以用这样的命令:$ curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 $ curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 $ curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3 $ curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.MP3这样就可以分块下载啦。不过你需要自己把这些破碎的文件合并起来如果你用UNIX或苹果,用 cat zhao.part* > zhao.MP3就可以如果用的是Windows,用copy /b 来解决吧,呵呵上面讲的都是http协议的下载,其实ftp也一样可以用。用法嘛,

$ curl -u name:passwd ftp://ip:port/path/file

或者大家熟悉的

$ curl ftp://name:passwd@ip:port/path/file

10)上传的option是-T

比如我们向ftp传一个文件:

$ curl -T localfile -u name:passwd ftp://upload_site:port/path/

当然,向http服务器上传文件也可以比如$ curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi注意,这时候,使用的协议是HTTP的PUT method刚才说到PUT,嘿嘿,自然让老服想起来了其他几种methos还没讲呢! GET和POST都不能忘哦。

11)POST和GET模式

$ curl http://www.linuxidc.com/login.cgi?user=nickwolfe

而POST模式的option则是-d

比如,$ curl -d "user=nickwolfe http://www.linuxidc.com/login.cgi

一点需要注意的是,POST模式下的文件上的文件上传,比如

这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:$ curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

https本地证书

$ curl -E localcert.pem https://remote_server再比如,你还可以用curl通过dict协议去查字典$ curl dict://dict.org/d:computer

目录
相关文章
|
1月前
|
网络协议 Linux 网络安全
curl(http命令行工具):Linux下最强大的网络数据传输工具
curl(http命令行工具):Linux下最强大的网络数据传输工具
44 0
|
5月前
|
Linux 网络安全
linux端口连通性测试telnet、wget、ssh、curl
linux端口连通性测试telnet、wget、ssh、curl
|
6月前
|
Linux
百度搜索:蓝易云 ,Linux下更新curl版本教程!
通过按照上述步骤,您可以成功更新Linux系统中的curl版本。请确保在更新之前备份任何重要数据,并在操作过程中仔细阅读和遵循curl源代码的相关文档和指南。
69 0
|
7月前
|
Linux
Linux下安装curl
Linux下安装curl
450 0
|
域名解析 网络协议 Linux
Linux - curl -w 参数详解
Linux - curl -w 参数详解
460 0
Linux - curl -w 参数详解
|
1天前
|
编解码 Linux 数据安全/隐私保护
linux工具之curl与wget高级使用
linux工具之curl与wget高级使用
|
4月前
|
Linux 定位技术
Linux命令(77)之curl
Linux命令(77)之curl
33 1
|
9月前
|
JSON 网络协议 Linux
说说 Linux 的 curl 命令
cURL,熟悉 Linux 的同学,没有人不知道这个命令吧:)我从实用性的角度,说下我比较常用的几个参数。
72 2
|
12月前
|
Linux
Linux实战笔记(一) curl基本使用
Linux实战笔记(一) curl基本使用
143 0
|
Web App开发 JSON Linux
linux Command curl
linux Command curl