Linux head command usage details (display the number of text blocks at the beginning)

Source: Internet
Author: User
The head and tail are just as easy to understand as their names. they are used to display a certain number of text blocks at the beginning or end, and the head is used to display the beginning of the file to the standard output, and tail is the end of the file.

The head and tail are just as easy to understand as their names. they are used to display a certain number of text blocks at the beginning or end, and the head is used to display the beginning of the file to the standard output, and tail takes it for granted that it is the end of the file.

1. command format:

Head [Parameters]... [file]...

2. command functions:

The head command is used to display the beginning of the file to the standard output. the default head command prints the first 10 lines of the corresponding file.

3. command parameters:

-Q: hide the file name.
-V: Display file name
-C <字节> Display the number of bytes
-N <行数> Number of lines displayed

4. example:

Instance 1: displays the first n rows of a file.

Command:

Head-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] # head-n 5 log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05 [root @ localhost test] #

Instance 2: displays the first n bytes of a file.

Command:

Head-c 20 log2014.log

Output:


Copy codeThe code is as follows:
[Root @ localhost test] # head-c 20 log2014.log
2014-01
2014-02
2014
[Root @ localhost test] #

Instance 3: Object content except the last n bytes

Command:

Head-c-32 log2014.log
Output:


Copy codeThe code is as follows:
[Root @ localhost test] # head-c-32 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] #

Example 4: all content except the last n rows of the output file

Command:

Head-n-6 log2014.log

Output:


Copy codeThe code is as follows:
[Root @ localhost test] # head-n-6 log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07 [root @ localhost test] #

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.