tail命令使用说明

1、命令概述

tail用于显示文件尾部的内容,默认在屏幕上显示指定文件的末尾10行。如果给定的文件不止一个,则在显示的每个文件前面加一个文件名标题。

2、命令语法
tail【选项】 【文件】 
3、命令选项

-f 显示文件最新追加的内容,该参数用于监视File文件增长。

-n Number 显示最后Number行

-c Number 显示最后Number字符

4、命令示例

4.1 -n 显示文件的最后2行,tail -n 2 b.txt 或者 tail -2 b.txt

 1 [root@localhost ~]# cat b.txt 
 2 a
 3 b
 4 c
 5 d
 6 e
 7 [root@localhost ~]# tail -n 2 b.txt 
 8 d
 9 e
10 [root@localhost ~]# tail -2 b.txt 
11 d
12 e

4.2 -c 显示文件的最后6个字符,tail -c 6 a.txt

1 [root@localhost ~]# cat a.txt 
2 safafdsagfergfdgdfger
3 dsfgergdfgerwgyregfdg
4 [root@localhost ~]# tail -c 6 a.txt 
5 egfdg

4.3显示文件file的内容,从第2行至文件末尾

 1 [root@localhost ~]# cat b.txt 
 2 a
 3 b
 4 c
 5 d
 6 e
 7 [root@localhost ~]# tail -n +2 b.txt 
 8 b
 9 c
10 d
11 e

4.4 -f 获取文件新增的内容,最后10行

 1 [root@localhost ~]# tail -f /var/log/messages 
 2 Oct 11 13:08:36 localhost systemd: Started Session 87 of user root.
 3 Oct 11 14:01:01 localhost systemd: Started Session 88 of user root.
 4 Oct 11 14:40:35 localhost systemd-logind: Removed session 83.
 5 Oct 11 15:01:01 localhost systemd: Started Session 89 of user root.
 6 Oct 11 15:54:41 localhost systemd: Started Session 90 of user root.
 7 Oct 11 15:54:41 localhost systemd-logind: New session 90 of user root.
 8 Oct 11 15:56:28 localhost systemd: Started Session 91 of user root.
 9 Oct 11 15:56:28 localhost systemd-logind: New session 91 of user root.
10 Oct 11 15:57:24 localhost systemd: Started Session 92 of user root.
11 Oct 11 15:57:24 localhost systemd-logind: New session 92 of user root.

猜你喜欢

转载自www.cnblogs.com/liuzgg/p/11654935.html