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 ...
随机推荐
- [Git]解决:error: The following untracked working tree files would be removed by checkout:
1 文由 不小心在本地对master分支做了修改,并commit了,但是没有push成功(因为处于防止代码提交风险,产品部对普通开发者没有项目master的push权限) 后来又经过了一顿骚操作(我已 ...
- LeeCode 318周赛复盘
T1: 对数组执行操作 思路:模拟 public int[] applyOperations(int[] nums) { int n = nums.length; for (int i = 0; i ...
- 升级:Logical Upgrade升级MySQL5.6.26
升级需谨慎,事前先备份 MySQL升级的实质是对数据字典的升级,数据字典有:sys.mysql.information_schema.performance_schema . MySQL升级的两种方式 ...
- asyncio的基本使用框架,python高效处理数据,asyncio.gather(),asyncio. create_task(),asyncio.run(main())
asyncio 是 Python 3.4 引入的标准库,是一个基于事件循环的异步 I/O 并发库.它提供了一种协作式的多任务处理方式,使得我们能够在一个线程中并发处理多个 I/O 操作.它通过将 I/ ...
- [C++基础入门] 1、C++初识
文章目录 1 C++初识 1.1 第一个C++程序 1.1.1 创建项目 1.1.2 创建文件 1.1.3 编写代码 1.1.4 运行程序 1.2 注释 1.3 变量 1.4 常量 1.5 关键字 1 ...
- Python变量的数据类型
主要内容 jupyter notebook的用法 变量 跟vi/vim的编辑模式很像 # 声明的三种格式 # 格式1 s1 = "我爱王晓静" # 格式2 s2 = s1 = &q ...
- count(列名)、count(1)和 count(*)有什么区别?
在MySQL中,这几个都是统计操作,很多人在使用的时候,都使用的是count(1),这有没有问题?使用正确?达到了统计效果? 我们从效果和效率两方面来分析下 执行效果 count(*) 包括了所有的列 ...
- UIOTOS:一款无门槛的前端0代码搭建工具
什么是UIOTOS? UIOTOS中文名称前端大师,是一款基于图形技术的前端0代码工具,支持通过连线和嵌套无门槛来搭建各类复杂的的交互界面,包括后台管理系统.组态数据大屏等,实现跟代码开发媲美的效果. ...
- 一文梳理z-index和层叠上下文
前言 最近参与某前端项目架构改造,发现项目中滥用z-index,设置的值有几十种并且不统一.在对项目的z-index进行梳理和统一过程中也深入学习了一下z-index,并撰写成文,希望也能帮助到陌生的 ...
- 2021-07-11:给定一个棵完全二叉树,返回这棵树的节点个数,要求时间复杂度小于O(树的节点数)。
2021-07-11:给定一个棵完全二叉树,返回这棵树的节点个数,要求时间复杂度小于O(树的节点数). 福大大 答案2021-07-11: 右树最左节点层数==左树最左节点层数,左树是满二叉树,统计左 ...