The tail command writes the file to the standard output from the specified point. Using the-f option of the tail command makes it easy to refer to the changing log file, Tail-f filename will display the tail contents of the filename on the screen, and not only refresh, so that you see the latest file content.
1. command format;
tail[necessary parameters [select parameters] [file]
2. Command function:
Used to display the content at the end of a specified file and to process it as input when no file is specified. Common view log files.
3. Command parameters:
-F Loop Read
-Q does not display processing information
-V Display detailed processing information
Number of-c< > bytes displayed
-n< number of rows > show rows
--pid=pid is shared with-F, which ends after the process id,pid dead.
-Q,--quiet,--silent never output the header of the filename
-S,--sleep-interval=s is shared with-F, which means sleeping s seconds at each repeated interval
4. Use instance:
Example 1: Display the end of a file
Command:
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]#
Description
Display the last 5 lines of the file
Example 2: Looping through the contents of a file
Command
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) bytes of data.
Bytes from 192.168.120.204:icmp_seq=1 ttl=64 time=0.038 ms
Bytes from 192.168.120.204:icmp_seq=2 ttl=64 time=0.036 ms
Bytes from 192.168.120.204:icmp_seq=3 ttl=64 time=0.033 ms
Bytes from 192.168.120.204:icmp_seq=4 ttl=64 time=0.027 ms
Bytes from 192.168.120.204:icmp_seq=5 ttl=64 time=0.032 ms
Bytes from 192.168.120.204:icmp_seq=6 ttl=64 time=0.026 ms
Bytes from 192.168.120.204:icmp_seq=7 ttl=64 time=0.030 ms
Bytes from 192.168.120.204:icmp_seq=8 ttl=64 time=0.029 ms
Bytes from 192.168.120.204:icmp_seq=9 ttl=64 time=0.044 ms
Bytes from 192.168.120.204:icmp_seq=10 ttl=64 time=0.033 ms
Bytes from 192.168.120.204:icmp_seq=11 ttl=64 time=0.027 ms
[Root@localhost ~]#
Description
Ping 192.168.120.204 > Test.log &//Ping the remote host in the background. and output files to Test.log; this practice is also used for more than one file monitoring. Use CTRL + C to terminate.
Example 3: Displaying files starting at line 5th
Command:
Tail-n +5 Log2014.log
Output:
[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
==============================
View a full set of articles: Http://www.bianceng.cn/OS/Linux/201301/35075.htm