Go Tail and head commands for Linux

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/carolzhang8406/article/details/6112707

The head command is used to view the contents of the previous lines of a specific file in the following format:

Head <filename>:

You can view the first few lines of a specific file through the Head command, which defaults to the first 10 lines, and if you want to see more of the above, you can set it up with a number option, such as:

Head-20 Install.log

You can view the contents of the previous 20 lines of this file by install.log the above command

In contrast to the head command, the tail command is used to view the contents of the next few lines of a specific file, by default, by viewing the contents of the last 10 lines of the file, as well as by using the number options if you want to see more of the following.

Tail-20 Install.log

You can also use tail to observe the process of the log file being updated. With the-f option, tail automatically
To display the new message in the open file to the screen. For example, to instantly observe changes in the/var/log/messages, as root user in the shell prompt
Type the following command:
Tail-f/var/log/messages

  Reads 4 to 39 rows of content

Function: Displays the number of lines after the specified file.

Syntax: tail [+/-num] [parameters] File

The meanings of each option in the tail command are:

+ num is displayed after the first num line.

-Num is displayed from the end of the file at NUM lines. If the num parameter is omitted, the system default value is 10.

L The count unit of the text behavior Num. When used in conjunction with the parameter option + NUM or-num option, NUM represents the number of lines of text to display.

The count unit of C in bytes Num. When used in conjunction with the parameter option + NUM or-num option, NUM represents the number of characters to display.

(l, C options can be omitted, the system default is L, that is, by row count).

Using the-f option of the tail command makes it easy to see the log files that are being changed, TAIL-F filename will display the most up-to-date content on the screen, and not only refresh, so you can view the latest file content.

Head command

If users want to see exactly what a file is saved, they can view only the first few lines of the file without having to browse the entire file. Use the head command to display only the first few lines of a file or standard input.

Syntax: Head [-n] File

Function: Displays the first few lines of the specified file.

Description: The command displays the first n rows of each specified file. If the n value is not given, the default setting is 10. If no file is specified, head is read from the standard input. For example, the first 3 lines of the file example.c are displayed.

$ head-3 example.c

/*-------------------------------------------*/

/* example1.c * /

/*-------------------------------------------*/

Go Tail and head commands for Linux

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.