linux grep基本用法--九五小庞
通过此语句可以查询一个文件或者当前目录下所有文件中包含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=yixiaoqatest6@sina.com, 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=yixiaoqatest6@sina.com, 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=yixiaoqatest6@sina.com, 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
linux grep基本用法--九五小庞的更多相关文章
- linux grep的用法
linux grep的用法<pre>[root@iZ23uewresmZ ~]# cat /home/ceshis.txtb124230 b034325 a081016 m7187998 ...
- LINUX系统新增及自动挂载硬盘-九五小庞
Linux系统下,添加新硬盘后,自动挂载的方法 1,列出所有硬盘,找到需要挂载的硬盘,例如/dev/vdb.输入: fdisk -l 2,查看硬盘是不是已经被挂载.一个硬盘不能重复挂载,已经挂 ...
- WinMTR 网络测试工具-九五小庞
WinMTR(建议优先使用) 百度下载工具 链接:https://pan.baidu.com/s/19ArKSTA2amsa4p6vHegDIQ 提取码:cy4y WinMTR是mtr工具在Windo ...
- VMware安装Centos7 -九五小庞
VMware安装Centos7超详细过程(图文) https://blog.csdn.net/babyxue/article/details/80970526 安装centos7的时候 启动会提示Pl ...
- centos7制作U盘启动盘-九五小庞
一.准备相关软件 1.8G以上U盘 2.UltraISO虚拟光驱(试用版即可)最新版 下载地址:https://cn.ultraiso.net/xiazai.html 点击下载试用 3.CentOS ...
- Oracle 11G R2安装说明 -九五小庞
教程版本Oracle 11.2.0.1.0
- 什么是Nginx -九五小庞
- Oracle错误 ora-12514 解决方法-九五小庞
成功连到数据库上之后,查看listener状态:lsnrctl status status READY 状态,需要由非归档转为归档模式,故操作如下: 1.关闭数据库shutdown immediate ...
- oracle创建/删除 用户,表空间-九五小庞
以下红色标示的都是可以修改的字段 可以按照如下顺序来创建表空间,创建用户,以及删除表空间,删除用户 查看oracle数据库已有的表空间路径 select name from v$datafile; 1 ...
- ORA-01033错误解决方案-九五小庞
Microsoft Windows [版本 6.3.9600](c) 2013 Microsoft Corporation.保留所有权利. C:\Users\Administrator>sqlp ...
随机推荐
- [数据分析与可视化] Python绘制数据地图2-GeoPandas地图可视化
本文主要介绍GeoPandas结合matplotlib实现地图的基础可视化.GeoPandas是一个Python开源项目,旨在提供丰富而简单的地理空间数据处理接口.GeoPandas扩展了Pandas ...
- Java对象内存管理
对象内存管理介绍 编译好的java程序需要运行在JVM中:JVM为java程序提供并管理所需要的内存空间:"栈"."堆"."方法区"三个区域 ...
- 1.使用cookie简单实现单点登录流程
1.动手 实现了简单使用多系统,单一位置同时登陆,以及注销 主要认证中心流程代码编写在为在sso-login包下的ViewConreoller和LoginController:各系统的用户名显示是写在 ...
- 浏览器层面优化前端性能(1):Chrom组件与进程/线程模型分析
现阶段的浏览器运行在一个单用户,多合作,多任务的操作系统中.一个糟糕的网页同样可以让一个现代的浏览器崩溃.其原因可能是一个插件出现bug,最终的结果是整个浏览器以及其他正在运行的标签被销毁. 现代操作 ...
- 手动编写Swagger文档与部署指南
Swagger介绍 在Web开发中,后端开发者在完成接口开发后,需要给前端相应的接口使用说明,所以一般会写一份API文档.一般来说,有两种方式提供API接口文档,一种是利用插件在代码中自动生成,另一种 ...
- TED--10 ways to have a better conversation
10 ways to have a better conversation All right, I want to see a show of hands: how many of you have ...
- Windows 11 启用 Hyper-V 之后网络上传速度异常慢解决方案
最近在开发用的台式机上启用了 Windows 的 Hyper-V 虚拟化功能,利用虚拟机运行了一台 Windows Server 2022 和 一台 Ubuntu Server,为了方便别的机器直接访 ...
- Netty服务端开发及性能优化
作者:京东物流 王奕龙 Netty是一个异步基于事件驱动的高性能网络通信框架,可以看做是对NIO和BIO的封装,并提供了简单易用的API.Handler和工具类等,用以快速开发高性能.高可靠性的网络服 ...
- 2023-2-22 增加产值冲减和EPC模块
应集团要求,现在已在综合信息管理系统中已增加以下信息,请大家注意,并及时转告业务人员: 1.[施工合同登记]模块增加必填字段"EPC建安费(万元)""EPC暂列费(万元) ...
- 2022-11-04:给定一个正数n,表示有多少个节点 给定一个二维数组edges,表示所有无向边 edges[i] = {a, b} 表示a到b有一条无向边 edges一定表示的是一个无环无向图,也
2022-11-04:给定一个正数n,表示有多少个节点 给定一个二维数组edges,表示所有无向边 edges[i] = {a, b} 表示a到b有一条无向边 edges一定表示的是一个无环无向图,也 ...