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效果一样

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [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查询出报错信息的行号,再通过上诉命令查询。

  • 相关阅读:
    第1章:程序设计和C语言(C语言入门)
    倒计时IE6+
    uploadify 使用 详细 说明
    HTTP 错误
    asp.net 向后台提交 html 代码段 包括 <> 标签
    C#使用NLog记录日志
    IE浏览器 location.href 不跳转
    .Net Core 导出Excel
    .net mvc 获取acion 返回类型
    sql sever 执行较大的文件脚本
  • 原文地址:https://www.cnblogs.com/wz123/p/12669478.html
Copyright © 2011-2022 走看看