How to use the tail command guide under Linux

  
                

If the head command is used to view the header of the file, then the tail command is just the opposite. The tail command is mainly used to view the end of the file content. The following small series will give you a detailed introduction to the use of tail under Linux.

1. Command format;

tail[required parameter][select parameter][file]

2. Command function:

Used to display the content at the end of the specified file. When no file is specified, it is processed as input information. Commonly used to view log files.

3. Command parameters:

-f Loop read

-q Do not display processing information

-v Display detailed processing information

-c"Number" Number of bytes displayed

-n "Number of lines" Display the number of lines

--pid=PID is used in conjunction with -f to indicate that the process ID and PID have died.

-q, --quiet, --silent Never output the header given the file name

-s, --sleep-interval=S with -f, indicating that each time Repeated interval sleep S seconds

4. Example:

Instance 1: Displaying the end of the 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:

Displaying the last 5 lines of the file

Example 2: Looping through the contents of the 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) 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< Br>

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 ~]#

Description:

ping 192.168.120.204 》 test.log & //ping the remote host in the background. And output the file to test.log; this method is also used for more than one file monitoring. Use Ctrl+c to terminate.

Example 3: Displaying files starting from line 5

Command:

tail -n +5 log2014.log

Output:

[root@localhost test]# cat log2014.log

2014-01

2014-02

2014-03

2014-04< Br>

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

================================================================================= Introduced, if you need to view the last few lines of the file, then you will use the tail command, you can refer to the above examples combined with the actual use.

Copyright © Windows knowledge All Rights Reserved