首页 > 系统相关 >linux grep基本用法--九五小庞

linux grep基本用法--九五小庞

时间:2023-07-04 09:12:16浏览次数:40  
标签:12 grep log -- 29 192.168 小庞 error 2015

通过此语句可以查询一个文件或者当前目录下所有文件中包含exception和error的文件
grep -E -i "((exception)|(error))" *

1.查找文件中是否存在指定的信息:

grep <查找信息> <文件名>

-bash-4.1$ grep exception error-2015-12-29.log
17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception
-bash-4.1$ vi error-2015-12-29.log
-bash-4.1$

2.在多个文件中查找:
grep <查找信息> <文件名> <文件名> ....
-bash-4.1$ grep ERROR error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception
error-2015-12-22.log:10:05:31.824 [http-/192.168.0.80:8080-10] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
error-2015-12-22.log:15:54:26.458 [http-/192.168.0.80:8080-6] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
-bash-4.1$

3.使用 -l 查找包含指定信息的文件名
grep -l <查找信息> <文件名> <文件名> ....
-bash-4.1$ grep -l ERROR error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log
error-2015-12-22.log

4.使用 -n 查找包含指定信息的文件名和行号

grep -l <查找信息> <文件名> <文件名> ....

-bash-4.1$ grep -n ERROR error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:1:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception
error-2015-12-22.log:1:10:05:31.824 [http-/192.168.0.80:8080-10] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
error-2015-12-22.log:2:15:54:26.458 [http-/192.168.0.80:8080-6] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10

5.使用 -v 查找不包含包含指定信息的文件名和行号
grep -V <查找信息> <文件名> <文件名> ....
-bash-4.1$ grep -v ERROR error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method getLinkEffectivenessByEmail in the service com.exiao.platform.core.supplier.service.LinkEffectivenessService. Tried 1 times of the providers [192.168.0.91:20880] (1/1) from the registry zk1.exiao.me:2181 on the consumer 192.168.0.80 using the dubbo version 2.5.3. Last error is: Invoke remote method timeout. method: getLinkEffectivenessByEmail, provider: dubbo://192.168.0.91:20880/com.exiao.platform.core.supplier.service.LinkEffectivenessService?anyhost=true&application=api-supplier-dubbo&check=false&default.check=false&default.retries=0&default.timeout=5000&dubbo=2.5.3&interface=com.exiao.platform.core.supplier.service.LinkEffectivenessService&methods=update,delete,getLinkEffectivenessByEmail,getLinkEffectivenessByEmailCode,create,findList,getByPK&pid=24014&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1450841202565, cause: Waiting server-side response timeout by scan timer. start time: 2015-12-29 17:49:08.844, end time: 2015-12-29 17:49:13.866, client elapsed: 0 ms, server elapsed: 5022 ms, timeout: 5000 ms, request: Request [id=2948, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=getLinkEffectivenessByEmail, parameterTypes=[class com.exiao.platform.core.supplier.model.LinkEffectivenessVO], arguments=[LinkEffectivenessVO [url=null, [email protected], effectiveTime=null,used=0,code=null,function=validate]], attachments={path=com.exiao.platform.core.supplier.service.LinkEffectivenessService, interface=com.exiao.platform.core.supplier.service.LinkEffectivenessService, timeout=5000, version=0.0.0}]], channel: /192.168.0.80:48178 -> /192.168.0.91:20880
error-2015-12-29.log: at com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke(FailoverClusterInvoker.java:101) ~[dubbo-2.5.3.jar:2.5.3]
error-2015-12-29.log: at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:227) ~[dubbo-2.5.3.jar:2.5.3]
error-2015-12-29.log: at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72) ~[dubbo-2.5.3.jar:2.5.3]
error-2015-12-29.log: at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52) ~[dubbo-2.5.3.jar:2.5.3]
error-2015-12-29.log: at com.alibaba.dubbo.common.bytecode.proxy4.getLinkEffectivenessByEmail(proxy4.java) ~[na:2.5.3]
error-2015-12-29.log: at com.exiao.platform.api.supplier.controller.LinkEffectivenessController.reSending(LinkEffectivenessController.java:42) ~[classes:na]
error-2015-12-29.log: at sun.reflect.GeneratedMethodAccessor1051.invoke(Unknown Source) ~[na:na]
error-2015-12-29.log: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
error-2015-12-29.log: at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]

6 使用 -R 在目标路径下递归查找指定信息:
grep -V <查找信息> <目标路径>

-bash-4.1$ grep -r ERROR ./
./default-2015-12-29.log:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception
./error-2015-12-22.log:10:05:31.824 [http-/192.168.0.80:8080-10] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
./error-2015-12-22.log:15:54:26.458 [http-/192.168.0.80:8080-6] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
./error-2015-12-24.log:09:57:24.202 [http-/192.168.0.80:8080-2] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
./error-2015-12-23.log:10:08:06.604 [http-/192.168.0.80:8080-11] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
./error-2015-12-29.log:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception<span style="font-size:18px;"><strong>
</strong></span>

7 使用 -i 查找信息时忽略大小写:
grep -i <查找信息> <文件名> <文件名> ....


-bash-4.1$ grep -i error error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception<span style="font-size:18px;"><strong><span style="color:#ff0000;">
</span></strong></span>


8.使用 -e 同时查找多个信息:
grep -e <查找信息> -e <查找信息> ... <文件名> <文件名> ....

-bash-4.1$ grep -e "ERROR" -e "Exception" error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:17:49:13.869 [http-/192.168.0.80:8080-12] ERROR c.e.p.f.w.i.SystemHanlderExceptionResolver[37] - system has exception
error-2015-12-29.log:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method getLinkEffectivenessByEmail in the service com.exiao.platform.core.supplier.service.LinkEffectivenessService. Tried 1 times of the providers [192.168.0.91:20880] (1/1) from the registry zk1.exiao.me:2181 on the consumer 192.168.0.80 using the dubbo version 2.5.3. Last error is: Invoke remote method timeout. method: getLinkEffectivenessByEmail, provider: dubbo://192.168.0.91:20880/com.exiao.platform.core.supplier.service.LinkEffectivenessService?anyhost=true&application=api-supplier-dubbo&check=false&default.check=false&default.retries=0&default.timeout=5000&dubbo=2.5.3&interface=com.exiao.platform.core.supplier.service.LinkEffectivenessService&methods=update,delete,getLinkEffectivenessByEmail,getLinkEffectivenessByEmailCode,create,findList,getByPK&pid=24014&revision=0.0.1-SNAPSHOT&side=consumer×tamp=1450841202565, cause: Waiting server-side response timeout by scan timer. start time: 2015-12-29 17:49:08.844, end time: 2015-12-29 17:49:13.866, client elapsed: 0 ms, server elapsed: 5022 ms, timeout: 5000 ms, request: Request [id=2948, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=getLinkEffectivenessByEmail, parameterTypes=[class com.exiao.platform.core.supplier.model.LinkEffectivenessVO], arguments=[LinkEffectivenessVO [url=null, [email protected], effectiveTime=null,used=0,code=null,function=validate]], attachments={path=com.exiao.platform.core.supplier.service.LinkEffectivenessService, interface=com.exiao.platform.core.supplier.service.LinkEffectivenessService, timeout=5000, version=0.0.0}]], channel: /192.168.0.80:48178 -> /192.168.0.91:20880
error-2015-12-29.log:Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2015-12-29 17:49:08.844, end time: 2015-12-29 17:49:13.866, client elapsed: 0 ms, server elapsed: 5022 ms, timeout: 5000 ms, request: Request [id=2948, version=2.0.0, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=getLinkEffectivenessByEmail, parameterTypes=[class com.exiao.platform.core.supplier.model.LinkEffectivenessVO], arguments=[LinkEffectivenessVO [url=null, [email protected], effectiveTime=null,used=0,code=null,function=validate]], attachments={path=com.exiao.platform.core.supplier.service.LinkEffectivenessService, interface=com.exiao.platform.core.supplier.service.LinkEffectivenessService, timeout=5000, version=0.0.0}]], channel: /192.168.0.80:48178 -> /192.168.0.91:20880
error-2015-12-22.log:10:05:31.824 [http-/192.168.0.80:8080-10] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
error-2015-12-22.log:15:54:26.458 [http-/192.168.0.80:8080-6] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10<span style="font-size:18px;"><strong>
</strong></span>


9 使用 -c 参数计算查找到的结果数量:
grep -c <查找信息> <文件名> <文件名> ....


-bash-4.1$ grep -c ERROR error-2015-12-29.log error-2015-12-22.log
error-2015-12-29.log:1
error-2015-12-22.log:2

其他一些用法:
使用管道将结果使用grep 过滤,输入包含指定信息的行

命令 | grep <匹配信息>

bash-4.1$ cat error-2015-12-22.log | grep ERROR
10:05:31.824 [http-/192.168.0.80:8080-10] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10
15:54:26.458 [http-/192.168.0.80:8080-6] ERROR c.e.p.f.fastdfs.FastDFSClientImpl[97] - recv package size -1 != 10<span style="font-size:18px;"><strong><span style="color:#ff0000;">
</span></strong></span>

还有其他一些参数如 -f , ^$,-A,-B,-C等 可自行查询用法.
————————————————
版权声明:本文为CSDN博主「wangxin0314」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wangxin1982314/article/details/50464259

 

标签:12,grep,log,--,29,192.168,小庞,error,2015
From: https://www.cnblogs.com/pxyblog/p/17524756.html

相关文章

  • Python爬虫简易教程
    步骤1.获取编程软件Python3Pycharm社区版(可选,更方便代码编辑)Python软件包requestsselenium requests和selenium的区别对于“xxx.html”类型地址的网页,他们的内容是静态的,这种网站一般不会做防护,可以直接用requests爬。其他类型的内容用selenium更节省时间一点。除......
  • 【LeetCode】矩阵中的和
    给你一个下标从0开始的二维整数数组nums。一开始你的分数为0。你需要执行以下操作直到矩阵变为空:矩阵中每一行选取最大的一个数,并删除它。如果一行中有多个最大的数,选择任意一个并删除。在步骤1删除的所有数字中找到最大的一个数字,将它添加到你的分数中。请你返回最......
  • 关闭vue项目中Uncaught runtime errors弹窗页面
    看控制台发现有webpack类名,应该是webpack搞出来的解決办法再vue.config.js中添加以下配置:module.exports=defineConfig({ ... devServer:{client:{overlay:false}}})......
  • 10. 拦截器
    1.拦截器概念​​‍(1)浏览器发送一个请求会先到Tomcat的web服务器(2)Tomcat服务器接收到请求以后,会去判断请求的是静态资源还是动态资源(3)如果是静态资源,会直接到Tomcat的项目部署目录下去直接访问(4)如果是动态资源,就需要交给项目的后台代码进行处理(5)在找到具......
  • 前端Vue自定义精美宫格菜单按钮组件 可设置一行展示个数 可设置成九宫格 十二宫格 十
    前端Vue自定义精美宫格菜单按钮组件可设置一行展示个数可设置成九宫格十二宫格十五宫格,下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13315效果图如下:cc-categoryMenu使用方法<viewclass="header">十五宫格菜单</view><!--推荐宫......
  • 公共语言运行库(CLR)开发系列课程(3):COM Interop基础 学习笔记
    公共语言运行库(CLR)开发系列课程(3):COMInterop基础学习笔记  上章地址什么是COMComponentObjectModel组建对象模型 基于接口(Interface)接口=协议IID标识接口V-table虚表方式调用单继承 对象(Object)实现一个或者多个接口举例:IDispatch......
  • 【笔试实战】LeetCode题单刷题-编程基础 0 到 1【二】
    1822. 数组元素积的符号题目链接1822. 数组元素积的符号题目描述已知函数 signFunc(x) 将会根据 x 的正负返回特定值:如果 x 是正数,返回 1 。如果 x 是负数,返回 -1 。如果 x 是等于 0 ,返回 0 。给你一个整数数组 nums 。令 product 为数组 nums......
  • 前端工程化实战-开发企业级CLI
    1.前言脚手架大家一定都不陌生,比如我们经常使用的vue-cli、create-react-app,它可以帮助我们快速的初始化一个项目,无需从零配置,极大的方便我们的开发。到这里你可能会疑惑,既然市面上有成熟的脚手架,为什么需要写一个属于自己的脚手架呢。因为公......
  • 图论练习
    图论练习学长的题果然恐怖如斯CF1458DFlipandReverse这个操作看着很奇怪\(0\)先看成\(-1\)那可操作的区间就是和为\(0\)对每一个前缀和的值建点,把每种元素看作边那可操作的区间就是一个环然后你会发现一个操作就是相当于是反着走这个环这里我们考虑连成无向边考虑连......
  • SpringBoot教学资料3-SpringBoot启动常见问题
    java.lang.RuntimeException:java.lang.RuntimeException:org.codehaus.plexus.component.repository.excMaven版本过高,与你使用的IDEA版本不兼容。推荐版本:maven3.6(建议)/maven3.9控制台Processterminatedhttps://blog.csdn.net/weixin_44589991/article/details/115013......