tail命令从指定点开始将文件写到标准输出,使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不断刷新,使你看到最新的文件内容。
【命令格式】
tail[必要参数][选择参数][文件]
【命令功能】
用于显示指定的文件末尾内容,不指定文件时,作为输出信息进行处理。常用于查看日志文件。
【命令格式】
-f 循环读取
-q 不显示处理信息
-v 显示详细的处理信息
-c<数目> 显示的字节数
-n<行数> 显示行数
-s,--sleep-interval=S 与-f合用,表示在每次反复间隔休眠S秒
-q,--quiet,--silent 从不输出给文件名的首部
--pid=PID 与-f合用,表示在进程ID,PID死掉之后结束。
【使用实例】
显示文件后五行内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@node1 ~] # cat my.cnf
[mysqld] datadir= /var/lib/mysql
socket= /var/lib/mysql/mysql .sock
user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
#######显示文件尾部内容##### [root@node1 ~] # tail -n 5 my.cnf
symbolic-links=0 [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
|
从第三行显示文件内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@node1 ~] # cat my.cnf
[mysqld] datadir= /var/lib/mysql
socket= /var/lib/mysql/mysql .sock
user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
########从第三行开始######## [root@node1 ~] # tail -n +3 my.cnf
socket= /var/lib/mysql/mysql .sock
user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error= /var/log/mysqld .log
pid- file = /var/run/mysqld/mysqld .pid
|
循环查看文件内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@node1 ~] # ping 172.16.18.6 > test.log &
[root@node1 ~] # tail -f test.log
PING 172.16.18.6 (172.16.18.6) 56(84) bytes of data. 64 bytes from 172.16.18.6: icmp_seq=1 ttl=64 time =0.407 ms
64 bytes from 172.16.18.6: icmp_seq=2 ttl=64 time =0.559 ms
64 bytes from 172.16.18.6: icmp_seq=3 ttl=64 time =0.485 ms
64 bytes from 172.16.18.6: icmp_seq=4 ttl=64 time =0.595 ms
64 bytes from 172.16.18.6: icmp_seq=5 ttl=64 time =0.610 ms
64 bytes from 172.16.18.6: icmp_seq=6 ttl=64 time =0.574 ms
64 bytes from 172.16.18.6: icmp_seq=7 ttl=64 time =0.887 ms
64 bytes from 172.16.18.6: icmp_seq=8 ttl=64 time =0.549 ms
64 bytes from 172.16.18.6: icmp_seq=9 ttl=64 time =0.447 ms
64 bytes from 172.16.18.6: icmp_seq=10 ttl=64 time =0.543 ms
64 bytes from 172.16.18.6: icmp_seq=11 ttl=64 time =0.552 ms
64 bytes from 172.16.18.6: icmp_seq=12 ttl=64 time =0.519 ms
|
本文转自 z永 51CTO博客,原文链接:http://blog.51cto.com/pangge/1337741