The tail command writes the file to the standard output from the specified point. you can use the-f option of the tail command to conveniently check the changing log file. tail-ffilename will display the tail content in filename on the screen and not only refresh, show you the latest file content
The tail command writes the file to the standard output from the specified point. you can use the-f option of the tail command to conveniently check the changing log file. the tail content of the filename is displayed on the screen and refreshed, so that you can see the latest file content.
1. command format;
Tail [required parameters] [select parameters] [files]
2. command functions:
Displays the content at the end of a specified file. If no file is specified, it is processed as an input. Common View log files.
3. command parameters:
-F: read cyclically
-Q: No processing information is displayed.
-V: displays detailed processing information.
-C <数目> Number of bytes displayed
-N <行数> Number of lines displayed
-- Pid = PID and-f are used together to indicate that the process ID ends after the PID dies.
-Q, -- quiet, -- silent never outputs the header of the given file name
-S, -- sleep-interval = S and-f are used together, indicating that the sleep seconds at each repeated interval
4. example:
Instance 1: displays the content at the end of a file.
Command:
Tail-n 5 log2014.log
Output:
Copy codeThe code is as follows:
[Root @ localhost test] # tail-n 5 log2014.log
2014-09
2014-10
2014-11
2014-12
============================ [Root @ localhost test] #
Note:
Display the last five lines of the file
Instance 2: view the file content cyclically
Command:
Tail-f test. log
Output:
Copy codeThe code is as follows:
[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 ~] #
Note:
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.
Instance 3: displays files from row 3
Command:
Tail-n + 5 log2014.log
Output:
Copy codeThe code is as follows:
[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
====================================
Supplement:
Purpose
Write the file to the standard output from the specified point. You can use the-f option of the tail command to conveniently check the changing log file. the tail content of the filename is displayed on the screen and refreshed, so that you can see the latest file content.
Syntax
Standard syntax
Tail [-f] [-c Number |-n Number |-m Number |-B Number |-k Number] [File]
Display rows in reverse order
Tail [-r] [-n Number] [File]
Description
The tail command writes the File specified by the File parameter to the standard output starting from the specified point. If no file is specified, standard input is used. The Number variable specifies the Number of units to be written to the standard output. The value of the Number variable can be a positive or negative integer. If the value is preceded by a plus sign, the file is written to the standard output starting with the number of units specified at the beginning of the file. If there is a minus sign before the value, the file is written to the standard output starting from the number of units specified at the end of the file. If no + (plus sign) or-(minus sign) exists before the value, read the file starting from the specified unit number at the end of the file.
The Number variable determines the unit type of the start point of the count by The-B,-c,-k,-m, and-n flags. If no flag is specified, the tail command reads the last 10 lines of the specified file and writes it to the standard output. This is the same as entering-n 10 in the command line.
The-m flag provides consistent results in the single-byte and double-byte character environments. When the input is a text file containing multi-byte characters, use the-c flag with caution, because the output may not start from the character boundary.
Flag
-B Number
Reads the specified file from the location of the 512-byte block indicated by the Number variable.
-C Number
Reads the specified file from the byte location indicated by the Number variable.
-F
If the input File is a regular File or if the File parameter specifies FIFO (first-in-first-out), the tail command will not terminate after the last specified unit of the input File is copied, instead, read and copy additional units from the input file (when these units are available ). If the File parameter is not specified and the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files being written by another process.
-K Number
Reads the specified file from the 1KB position indicated by the Number variable.
-M Number
Reads the specified file from the multi-byte character position indicated by the Number variable. Use this flag to provide consistent results in the single-byte and double-byte character code set environments.
-N Number
Reads the specified file from the row location indicated by the Number variable.
-R
The output is displayed in reverse order from the end of the file. The default value of the-r flag is to print the entire file in reverse order. If the file is larger than 20,480 bytes, the-r flag only displays the last 20,480 bytes.
The-r flag is valid only when it is used together with the-n flag. Otherwise, it will be ignored.
Exit status
This command returns the following exit values:
0
Completed successfully.
> 0
An error occurs.
Example
To display the last 10 lines of the notes file, enter:
The number of rows to be read from the end of the notes file in tail notes. enter:
Tail-n 20 notes
To display a page of notes files each time starting from 200th bytes, enter:
Tail-c + 200 notes | pg
To track file growth, enter:
Tail-f accounts
This shows the last 10 rows of the accounts file. The tail command continues to display the rows added to the accounts file. The display continues until you press Ctrl-C to stop.
File
/Usr/bin/tail
Contains the tail command.