The Tail command writes the file to standard output starting at the specified point. Using the-f option of the tail command makes it easy to see the log files that are being changed, TAIL-F filename will display the most trailer in filename on the screen, and not only refresh, Enables you to see the latest file content.
1. command format;
tail[necessary parameters [selection parameters] [file]
2. Command function:
Used to display the content at the end of the specified file, and is processed as input when the file is not specified. Common view log files.
3. Command parameters:
-F Loop Read
-Q does not display processing information
-V displays detailed processing information
Number of-c< > bytes displayed
-n< lines > Display rows
--pid=pid is shared with-F, which means that the process ends after the id,pid dies.
-Q,--quiet,--silent never output the header of the file name
-S,--sleep-interval=s is combined with-F, which means sleep s seconds at each repetition interval
4. Usage examples:
Example 1: Displaying the end of a file
Command:
5 Log2014.log
Output:
1 [[email protected] test]# tail-n 5< /span> Log2014.log 2 3 2014 -09 4 5 2014 -10 6 7 2014 -11 9 2014 -12 10 11 ==============================[[email protected] test]#
Description
Displays the last 5 lines of the file
Example 2: Looping through the contents of a file
Command:
Tail-f Test.log
Output:
1[[email protected] ~]# Ping192.168.120.204> Test.log &2[1]11891[Email protected] ~]# tail-F Test.log3Ping192.168.120.204(192.168.120.204) About( -) bytes of data.4 -bytes from 192.168.120.204: icmp_seq=1Ttl= -Time=0.038Ms5 -bytes from 192.168.120.204: icmp_seq=2Ttl= -Time=0.036Ms6 -bytes from 192.168.120.204: icmp_seq=3Ttl= -Time=0.033Ms7 -bytes from 192.168.120.204: icmp_seq=4Ttl= -Time=0.027Ms8 -bytes from 192.168.120.204: icmp_seq=5Ttl= -Time=0.032Ms9 -bytes from 192.168.120.204: icmp_seq=6Ttl= -Time=0.026MsTen -bytes from 192.168.120.204: icmp_seq=7Ttl= -Time=0.030Ms One -bytes from 192.168.120.204: icmp_seq=8Ttl= -Time=0.029Ms A -bytes from 192.168.120.204: icmp_seq=9Ttl= -Time=0.044Ms - -bytes from 192.168.120.204: icmp_seq=TenTtl= -Time=0.033Ms - -bytes from 192.168.120.204: icmp_seq= OneTtl= -Time=0.027Ms the[Email protected] ~]#
Description
Ping 192.168.120.204 > Test.log &//Ping remote host in background. and output files to Test.log; This practice also allows for more than one file to monitor. Use CTRL + C to terminate.
Example 3: Displaying a file starting from line 5th
Command:
Tail-n +5 Log2014.log
Output:
1 [email protected] test]# cat Log2014.log2 the- on3 the- Geneva4 the-Geneva5 the-Geneva6 the- to7 the- .8 the- -9 the- ,Ten the- the One the-Ten A the- One - the- A -============================== the[Email protected] test]# Tail-n +5Log2014.log - the- to - the- . - the- - + the- , - the- the + the-Ten A the- One at the- A -==============================
The tail command for Linux learning