linux进阶命令
1 curl命令
文件上传下载命令,综合传输工具
支持 DICT 、FILE、FTP、FTPS、HTTP、HTTPS、IMAP命令
不能交互
代理
curl –x 127.0.0.1:8888 https://www.baidu.com
get:发送get请求
-G:使用get请求
-d:指定请求数据
curl –G https://www.baidu.com
curl –X GET https/www.baidu.com
post
-d:指定post请求体
curl –d ‘login=1234’ https://www.baidu.com
curl –X POST https://www.baidu.com
other
保存响应内容
curl –o tmp.html https://www.baidu.com
输出通信的整个过程
curl –v https://www.baidu.com
不输出错误和进度信息
curl –s https://www.baidu.com
jq
jq是一个过滤器
安装:yum install -y jq
使用
. 格式优化
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}'| jq '.'
内容提取
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a
从数组中提取所有数据
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq '.[]'
从数组中提取单个数据
echo '[{"aa":11,"ab":"bc","ad":22},{"ae": 12,"af":"bd","ag":35},{"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}]' | jq '.[0]'
过滤多个值
echo '[{"aa":11,"ab":"bc","ad":22},{"ae": 12,"af":"bd","ag":35},{"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}]' | jp '.[0,1]'
数据重组成数组
echo ‘{“a”:1,”b”:2,“c”:3,”d”:4}’ | jq ‘[.a,.b]’
数据重组成对象
echo ‘{“a”:1,”b”:2,“c”:3,”d”:4}’ | jq ‘{“tmp”:.b}’
输出指定元素
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '.[0] | {aa:.aa}'
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '.[0] | {aa:.ab}'
取出单个值
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '.[0] |.aa'
输出数组
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '[.[0] ]'
修改keys
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '.[0] |{ms_doc:.aa} '
取出keys值
echo '{"a": [{"aa":11,"ab":"bc","ad":22}, {"ae":12,"af":"bd","ag":35}],"b": [{"ba":123,"bc":"abc","bd":46}, {"be":"hello","bf":76,"bg":"cc"}]}' | jq .a | jq '.[0] | [.[]]'