首页 > 系统服务 > 详细

linux查找日志技巧

时间:2020-06-11 15:11:50      阅读:50      评论:0      收藏:0      [点我收藏+]

1.cat -n test.log |grep "李明"   ps:查找日志中关键字为“李明”出现的行号

1>得到"李明"关键字所在的行号是102行. 此时如果我想查看这个关键字前10行和后10行的日志:

cat -n test.log |tail -n +92|head -n 20

tail -n +92表示查询92行之后的日志

head -n 20 则表示在前面的查询结果里再查前20条记录

2. cat -n test.log |grep "李明" |more 可带翻页,空格键翻页。

3.tail  -n  10  test.log   查询日志尾部最后10行的日志;

4.tail -n +10 test.log    查询10行之后的所有日志;

5.head -n 10  test.log   查询日志文件中的头10行日志;

6.head -n -10  test.log   查询日志文件除了最后10行的其他所有日志;

 

linux查找日志技巧

原文:https://www.cnblogs.com/BJhao-liu/p/13092542.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!