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查询出报错信息的行号,再通过上诉命令查询。

  • 相关阅读:
    git commit --amend
    Interleaving String leetcode
    Longest Common Substring
    Distinct Subsequences Leetcode
    Longest Common Subsequence
    Palindrome Partitioning II Leetcode
    百度面试时遇到这样一个问题:给定数组a[];计算除最后一个元素之外其他元素的和,下面的代码有什么问题吗
    sizeof与strlen
    网络是怎么连接的(2)?
    网络是怎么连接的(1)?
  • 原文地址:https://www.cnblogs.com/gexiaoshan/p/9923807.html
Copyright © 2011-2022 走看看