Linux tail command analysis

Source: Internet
Author: User
Linux tail command analysis 1. to view the first five lines of a file, you can use the head command, such as head-5/etc/passwd2. to view the last 10 lines of the file, you can use the tail command, such: tail-2/etc/passwd or tail-n2/etc/passwdtail-f/var/log... linux tail command analysis 1. to view the first five lines of a file, run the head command, for example, head-5/etc/passwd 2. run the tail command to view the last 10 lines of the file, for example: tail-2/etc/passwd or tail-n 2/etc/passwd tail-f/var/log/messages parameter-f keeps tail reading the latest content, this has the effect of real-time monitoring. use Ctrl + c to terminate it! 3. view the middle section of the file. you can use the sed command, for example, sed-n'5, 10p'/etc/passwd. in this way, you can only view lines 5th to 10th of the file. Syntax format: tail [-f] [-c Number |-n Number |-m Number |-B Number |-k Number] [File] or tail [-r] [-n Number] [File] www.2cto.com 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
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 (+), it starts with the file.
The specified number of units starts to write the file to the standard output. If there is a minus sign before the value, the file will be written from the number of units specified at the end of the file
Standard output. 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 parameter www.2cto.com:-B Number reads the specified file from the 512-byte block position 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 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 environments. -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 is displaced 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. The-r flag is valid only when it is used together with the-n flag. Otherwise, the author youngJava will be ignored.
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.