linux查看日志常用命令收集

1、实时监控日志
tail -f test.log

2、实时监控当前100行日志
tail -100f test.log

3、查看最新的100行日志(-n表示显示行号)
tail -n 100 test.log

4、查看除了头100行以外的所有日志
tail -n +100 test.log

5、查看头100行日志
head -n 100 test.log

6、查看除了最后100以外的所有日志
head -n -100 test.log

7、正序查找日志中的关键字
cat -n test.log | grep "exception"
ps:如果查到的日志很多,可以使用more进行分页
cat -n test.log | grep "exception" | more

8、获取到了关键字的行号,要查看行号附近日志,比如要查看行号为100附近的日志
cat -n test.log | grep "exception" | tail -n +90 |head -n 20
ps:cat -n test.log | grep "exception" | tail -n +90 展示的是90行以后的所有日志
ps:后面再跟上head -n 20 表示在前面的基础上只查看前20条日志,相当于查看90~110之间的日志

9、倒叙查找关键字日志
tac -n test.log | grep "exception"

10、将日志保存到文件中
cat -n test.log | grep "exception" > test.txt

11、定位到日志结尾
shift + g

12、从下往上查找
shift + n

13、根据日期查询日志
sed -n '/2019-07-26 11:12:05.842/,/2019-07-26 11:12:05.901/p' htjf-account-web.log
ps:查询的日期在日志中要有

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值