linux查看日志

find -type f -name “*.log” |xargs grep “reportId”

find -type f -name ".log" |xargs grep “reportId”
find -type f -name '
.php’|xargs grep ‘hello,world!’

cat *.log | grep “hahahah”

##查看日志

1.查看实时日志:
tail -f nohup.out

2.分页查看所有日志:
cat nohup.out | more

4.分页查看前N行日志:
tail -n 1000 nohup.out | more

5.查看实时日志并检索关键字:
tail -f nohup.out | grep “关键字”

6.检索日志,并显示该条日志的前后N行记录:
cat nohup.out | grep -n -B10 -A10 “关键字”

7.查看日志,从第1000行开始,显示500行:
cat nohup.out | tail -n +1000| head -n 500

8.查看日志,显示1000行到1500行:
shell cat nohup.out | head -n 1500| tail -n +1000

9.删除包括关键词的行:
sed -i ‘/关键词/d’ nohup.out

Linux查看日志常用命令
1.查看日志常用命令
tail:
-n 是显示行号;相当于nl命令;例子如下:
tail -100f test.log 实时监控100行日志
tail -n 10 test.log 查询日志尾部最后10行的日志;

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

head:  

    跟tail是相反的,tail是看后多少行日志;例子如下:

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

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

cat: 

    tac是倒序查看,是cat单词反写;例子如下:

        cat -n test.log |grep "debug"   查询关键字的日志
  1. 应用场景一:按行号查看—过滤出关键字附近的日志

    1)cat -n test.log |grep “debug” 得到关键日志的行号

    2)cat -n test.log |tail -n +92|head -n 20 选择关键字所在的中间一行. 然后查看这个关键字前10行和后10行的日志:

         tail -n +92表示查询92行之后的日志
    
         head -n 20 则表示在前面的查询结果里再查前20条记录
    
  2. 应用场景二:根据日期查询日志

    sed -n ‘/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p’ test.log

    特别说明:上面的两个日期必须是日志中打印出来的日志,否则无效;

     先 grep '2014-12-17 16:17:20' test.log 来确定日志中是否有该 时间点
    

4.应用场景三:日志内容特别多,打印在屏幕上不方便查看
(1)使用more和less命令,

       如: cat -n test.log |grep "debug" |more     这样就分页打印了,通过点击空格键翻页

(2)使用 >xxx.txt 将其保存到文件中,到时可以拉下这个文件分析

        如:cat -n test.log |grep "debug"  >debug.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值