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 ...
随机推荐
- [数据库]MySQL之备份与恢复【未完待续】
1 恢复 方式一 source sqlFile.sql 登陆MySQL 创建数据库db (create database db;) 进入/使用 数据库db (use db;) 将要导入的sql文件放到 ...
- FormData收集表单信息&并且转化为Json格式进行提交验证
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- abp(net core)+easyui+efcore实现仓储管理系统——供应商管理升级之上(六十三)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...
- LeetCode 周赛 344(2023/05/07)手写递归函数的固定套路
本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问. 大家好,我是小彭. 今天下午有力扣杯战队赛,不知道官方是不是故意调低早上周赛难度给选手们练练手. 往期周赛回 ...
- Laf Assistant:云开发从未如此爽快!
原文链接:https://forum.laf.run/d/67 工欲善其事,必先利其器.在编写代码时,IDE 也是我们不可或缺的.它可以让我们更高效地完成代码编写,提高开发效率.因此,IDE 是我们编 ...
- Centos7 部署Django项目 uwsgi + nginx
启动 首先确保你的django项目是可以在虚拟环境中跑起来的,环境管理窝用的是pyenv,pyenv不知道什么东西的可以参考窝之前写过的Pyenv环境管理的安装文. 项目启动 python manag ...
- 项目打包后配置到node服务器
1.将项目进行打包 npm run build项目根目录下会多出一个打包好的由.js .html .css文件组成的dist文件夹,如图 2.搭建node微型服务器 新建文件夹命名"no ...
- 2023-02-11:给你两个整数 m 和 n 。构造一个 m x n 的网格,其中每个单元格最开始是白色, 请你用 红、绿、蓝 三种颜色为每个单元格涂色。所有单元格都需要被涂色, 涂色方案需要满足:
2023-02-11:给你两个整数 m 和 n .构造一个 m x n 的网格,其中每个单元格最开始是白色, 请你用 红.绿.蓝 三种颜色为每个单元格涂色.所有单元格都需要被涂色, 涂色方案需要满足: ...
- 2022-07-22:以下go语言代码输出什么?A:1;B:1.5;C:编译错误;D:1.49。 package main import “fmt“ func main() { var i
2022-07-22:以下go语言代码输出什么?A:1:B:1.5:C:编译错误:D:1.49. package main import "fmt" func main() { v ...
- 2021-03-27:给你一个链表的头节点 head ,旋转链表,将链表每个节点向右移动 k 个位置。输入:head = 1→2→3→4→5, k = 2,输出:4→5→1→2→3。
2021-03-27:给你一个链表的头节点 head ,旋转链表,将链表每个节点向右移动 k 个位置.输入:head = 1→2→3→4→5, k = 2,输出:4→5→1→2→3. 福大大 答案20 ...