Linux Base Command (OS) head command

Source: Internet
Author: User

Head and tail are as straightforward as its name, which is used to show a certain number of blocks of text at the beginning or end, which is used to show the beginning of the file to the standard output, while tail assumes the end of the file.

1. Command format:

Head [parameters] ... [File] ...

2. Command function:

The head is used to display the opening of the file to standard output, and the default head command prints the first 10 lines of its corresponding file.

3. Command parameters:

-Q Hide File name

-V Display file name

-c< bytes > Display byte count

-n< rows > number of rows displayed

4. Use instance:

Example 1: Display the first n rows of a file

Command:

Head-n 5 Log2014.log

Output:

[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: Displaying the first n bytes of a file

Command:

Head-c Log2014.log

Output:

[Root@localhost test]# head-c Log2014.log

2014-01

2014-02

2014

[Root@localhost test]#

Instance 3: The contents of the file other than the last n bytes

Command:

Head-c -32 Log2014.log

Output

[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]#

Instance 4: The output file contains all but the last n rows

Command:

Head-n-6 Log2014.log

Output:

[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]#

View a full set of articles: Http://www.bianceng.cn/OS/Linux/201301/35075.htm

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.