How Linux displays a few lines of a file (in the middle of a few lines)

Source: Internet
Author: User

Tail command---in linux for viewing file contents

The most basic are cat, more and less.
1. If you want to see only the first 5 lines of the file, you can use the Head command, such as:
Head-5/etc/passwd
2. If you want to view the following 10 lines of the file, you can use the tail command, such as:
TAIL-10/ETC/PASSWD or Tail-n 10/etc/passwd
Tail-f/var/log/messages
The parameter-F enables tail to read the latest content continuously, so that the effect of real-time monitoring is terminated with CTRL + C!
3. To view the middle section of the file, you can use the SED command, such as:
Sed-n ' 5,10p '/etc/passwd
This allows you to view only lines 5th through 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 files specified by the file parameter to standard output, starting at the specified point. If no file is specified, standard input is used. The number variable specifies how many cells are written to 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 standard output starting at the number of cells specified at the beginning of the file. If the value is preceded by a-(minus sign), the file is written to standard output starting at the number of cells specified at the end of the file. If the value is preceded by A + (plus sign) or-(minus sign), the file is read from the unit number specified at the end of the file.
Main parameters:

-B number starts reading the specified file from the 512-byte block position represented by the number variable.
-c number reads the specified file starting at the byte position represented by the number variable.
-F If the input file is a regular file or if the filename parameter specifies a FIFO (first in, out), then the tail command does not terminate after the last specified unit of the input file is copied, but continues to read and copy additional units from the input file (when those cells 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 that another process is writing.
-K number reads the specified file starting at the 1KB block position represented by the number variable.
-m number starts reading the specified file from the multibyte character position represented by the # variable. Use this flag to provide consistent results in a single-byte and double-byte character code set environment.
-N number reads the specified file from the first or last row position, represented by the sign of the number variable (+ or-or none), and is shifted by the Line No.
-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, then the-r flag displays only the last 20,480 bytes. The-r flag is valid only with the-n flag. Otherwise, it will be ignored.

Transferred from: http://www.cnblogs.com/wangkangluo1/archive/2012/05/26/2518856.html

How Linux displays a few lines of a file (in the middle of a few lines)

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.