2. tail -f catalina.out
3. In this way, you can view the running log in real time when running
Ctrl+c is to exit the tail command.
By the way, let's talk about the tail command in linux
The tail command starts writing the file to the standard output from the specified point. Use the -f option of the tail command to easily view the log file that is being changed. tail -f filename will display the last content in filename on the screen, and not only refresh , so you can see the latest file contents.
1. command format ;
tail[required parameter][optional parameter][file]
2. Command function:
It is used to display the content at the end of the specified file. When no file is specified, it is processed as input information. Commonly viewed log files .
3. Command parameters:
-f loop read
-q do not display processing information
-v display detailed processing information
-c <number> number of bytes to display
-n<number of lines> Display the number of lines
--pid=PID is used with -f, which means that it will end after the process ID and PID die.
-q, --quiet, --silent never output headers given filenames
-s, --sleep-interval=S Combined with -f, it means to sleep for S seconds at the interval of each repetition
4. Example of use:
Example 1: Display the content at the end of the file
Order:
tail -n 5 log2014.log
output:
[root@localhost test]# tail -n 5 log2014.log
2014-09
2014-10
2014-11
2014-12
==============================[root@localhost test]#
illustrate:
Display the last 5 lines of the file
Example 2: Loop through the file content
Order:
tail -f test.log
output:
[root@localhost ~]# ping 192.168.120.204 > test.log &
[1] 11891[root@localhost ~]# tail -f test.log
PING 192.168.120.204 (192.168.120.204) 56(84) bytes of data.
64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms
64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms
64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 time=0.027 ms
[root@localhost ~]#
说明:
ping 192.168.120.204 > test.log & //在后台ping远程主机。并输出文件到test.log;这种做法也使用于一个以上的档案监视。用Ctrl+c来终止。
实例3:从第5行开始显示文件
命令:
tail -n +5 log2014.log
输出:
[root@localhost test]# cat log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
[root@localhost test]# tail -n +5 log2014.log
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================