Tail command in inux --- used to View File Content
Source: Internet
Author: User
Linux tail command-used to View File Content
The most basic options are cat, more, and less.
1. If you only want to view the first five lines of the file, you can use the head command, for example:
Head-5/etc/passwd
2. If you want to view the last 10 lines of the file, you can use the tail command, such:
Tail-2/etc/passwd or tail-N 2/etc/passwd
Tail-F/var/log/messages
Parameter-F keeps tail reading the latest content, so that it can be monitored in real time and ended with Ctrl + C!
3. view the middle part of the file. You can use the SED command, for example:
Sed-n'5, 10p'/etc/passwd
In this way, you can only view rows 5th to 10th of the file.
Tail syntax format:
Tail [-F] [-C number |-N number |-M number |-B number |-K number] [file]
Or
Tail [-R] [-N number] [file]
Instructions for use:
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. Number variable <br/> 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 specified number of units at the beginning of the file <br/>. 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.
Main parameters:
-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, but will continue
Read and copy additional units from the input file (when these units are available ). If the file parameter is not specified,
If the standard input is a pipe, the-F flag is ignored. The tail-F command can be used to monitor another process
The number of written files increases.
-K Number reads the specified file from the 1kb block location 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 environment.
-N number reads the specified file from the first or last row. The position is indicated by the number variable symbol (+ or-or none)
And shift by the number of the row.
-R displays the output in reverse order from the end of the file. The default value of the-r flag is to display 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. -R flag only
It is valid only when it is used together with the-n mark. Otherwise, it will be ignored.
Input
Tail-B + 1 file
Tail-C + 1 file
Tail-n + 1 file // The Position of the first line from the start
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.