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 命令相结合

扫描二维码关注公众号,回复: 3972065 查看本文章

现在若有显示第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查询出报错信息的行号,再通过上诉命令查询。

猜你喜欢

转载自www.cnblogs.com/gexiaoshan/p/9923807.html