Welcome to github.com/hsfxuebao/j… , hope to help you, if you feel ok, please click on the Star

The tail command writes the file to standard output starting at the specified point. You can use the -f option of the tail command to easily check the log file that is being changed. Tail -f filename displays the tail content of filename on the screen and refreshes it to see the latest file content.

1. Command format;

Tail [required parameters][Selection parameters][file]

2. Run the following command:

Displays the content at the end of a specified file. If no file is specified, the file is processed as input information. View log files frequently.

3. Command parameters:

-v Displays detailed processing information. -c< Number > Number of bytes to display. -n< number of lines to display. – Silent does not output the header of the given file name. -s. – sleep-interval= s is used with -f, indicating that sleep is seconds at each repeated interval

4. Example:

Example 1: Run the tail -n 5 log2014. Log command to display the contents at the end of the file.

[root@localhost test]# tail -n 5 log2014.log 
2014-09
2014-10
2014-11
2014-12
==============================[root@localhost test]#123456
Copy the code

Example 2: Run the tail -f test.log command to loop the contents of the file. Output: tail -f test.log

[root@localhost ~]# ping 192.168.120.204 > test.log & [1] 11891[root@localhost ~]# tail -f test.log ping 192.168.120.204 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.027ms [root@localhost ~]# And output the file to test.log; This practice is also used for monitoring more than one file. Use Ctrl+ C to terminate. 1234567891011121314151617Copy the code

Example 3: Display the file from line 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 The 2014-08, 2014-09 2014-10 2014-11-12 2014 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =Copy the code

From:

One Linux command per day (15) : tail command