Linux常用命令-tail

命令

tail

描述

output the last part of files
查看文件后几行

用法

1
tail [OPTION]... [FILE]...

选项

1
2
3
4
5
Options:
-c 显示文件的后几个字节
-f 实时追加显示文件新增内容,等同于tailf命令
-n 显示文件的后几行,可以简写,如-n 5简写为-5
-v 显示文件名

注意

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ tail -5 a
16
17
18
19
20
$ tail -n3 a
18
19
20
# 显示文件后3行并且显示文件名
$ tail -vn3 a b
==> a <==
18
19
20

==> b <==
18
19
20

# 实时显示文件新增内容
$ tail -f /var/log/messages
Feb 8 15:00:01 centos7 systemd: Started Session 18 of user root.
Feb 8 15:00:21 centos7 systemd: Time has been changed
Feb 8 15:01:03 centos7 systemd: Started Session 19 of user root.
Feb 8 15:01:27 centos7 systemd: Time has been changed
Feb 8 15:02:33 centos7 systemd: Time has been changed

$ tailf /var/log/messages
Feb 8 15:07:58 centos7 systemd: Time has been changed
Feb 8 15:09:02 centos7 systemd: Time has been changed
Feb 8 15:10:01 centos7 systemd: Started Session 20 of user root.
Feb 8 15:10:05 centos7 systemd: Time has been changed