zoukankan      html  css  js  c++  java
  • centos 查看日志

    显示文件

      显示前3行数据

      ls -l|head -n 3

      显示后3行数据

      ls -l|tail -n 3

    显示文件内容

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

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

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

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

    关键字查找

      cat -n test.log |grep "地形"  得到关键日志的行号

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

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

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

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

    按时间段查询

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

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

        使用more和less命令, 如: cat -n test.log |grep "地形" |more 分页方便查看

        cat -n test.log |grep "地形"  >xxx.txt 存储到本地文件

    日志实时监控

      tail -f test.log

    vim关键字查看日志

      vim test.log

      /+关键字 ,回车即可。此为从文档当前位置向下查找关键字,按n键查找关键字下一个位置

      ?+关键字,回车即可。此为从文档挡圈位置向上查找关键字,按n键向上查找关键字

  • 相关阅读:
    android作业10.21
    安卓10.7作业
    安卓9.30
    9.23作业
    9.17安卓作业
    6.12作业
    5.29作业
    5.28上机作业
    leetcode 219
    策略模式
  • 原文地址:https://www.cnblogs.com/agasha/p/14078291.html
Copyright © 2011-2022 走看看