zoukankan      html  css  js  c++  java
  • linux 日志文件查看

    记录下日志中常用的日志查看命令。

    1.  tail -n 10 -f  **.log

    显示日志文件尾部10行日志,当有新日志产生,会追加显示。

    2. tail 命令

    现ff.sh中有如下信息:

    [root@hxjk_test_backend_services test]# cat ff.sh
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    tail -n 5 ff.sh 显示文件后5行日志和tail -n  -5 ff.sh效果一样

    [root@hxjk_test_backend_services test]# tail -n 5 ff.sh
    15
    16
    17
    18
    19
    [root@hxjk_test_backend_services test]# tail -n -5 ff.sh
    15
    16
    17
    18
    19
    [root@hxjk_test_backend_services test]# 
    

    tail -n  +5 ff.sh 显示的是第5行开始到底部的日志

    [root@hxjk_test_backend_services test]# tail -n +5 ff.sh
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    [root@hxjk_test_backend_services test]# 

    3. head 命令

    head -n 5 ff.sh 显示前5行日志 和head -n +5 ff.sh 效果一样

    [root@hxjk_test_backend_services test]# head -n 5 ff.sh
    1
    2
    3
    4
    5
    [root@hxjk_test_backend_services test]# head -n +5 ff.sh
    1
    2
    3
    4
    5
    [root@hxjk_test_backend_services test]# 

    head -n -5 ff.sh 显示后5行到头的所有信息

    [root@hxjk_test_backend_services test]# head -n -5 ff.sh
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@hxjk_test_backend_services test]# 

    4. cat tail head 命令相结合

    现在若有显示第10行前后5条数据,可如下查询

    [root@hxjk_test_backend_services test]# cat -n ff.sh|tail -n +5|head -n 11
         5    5
         6    6
         7    7
         8    8
         9    9
        10    10
        11    11
        12    12
        13    13
        14    14
        15    15
    [root@hxjk_test_backend_services test]# 

    所以在实际使用中若要查询日志文件中报错信息时,可先通过grep查询出报错信息的行号,再通过上诉命令查询。

  • 相关阅读:
    Java Web
    对象拷贝
    多线程
    容器
    新鲜出炉一份Java面试清单,共200+道题
    优秀博客
    【安防】自动光圈控制
    【硬件】变压器的电特性参数
    【工作总结】IPD开发管理流程
    【EMC】EMI滤波器
  • 原文地址:https://www.cnblogs.com/gexiaoshan/p/9923807.html
Copyright © 2011-2022 走看看