In the Linux system, the head command instance is explained in detail.

  

When we need to view the header of the file, we need to use the head command. The head command is mainly used to check the contents of the first few lines or bytes of the file. Let's take a look at the usage of the head command under Linux.

1. Command format:

head [parameter]. . [File]. . .

2. Command function:

head is used to display the beginning of the file to the standard output. 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 "Byte" Display byte number

-n Number of lines shows the number of lines

4. Example:

Example 1: Displaying the first n lines 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]#

Example 2: Displaying the first n bytes of a file

Command:

head -c 20 log2014.log

Output:

[root@localhost test]# head -c 20 log2014.log

2014-01

2014-02

2014

[root@localhost test]#

3: Content of the file except 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]#

Example 4: Output file except the last n lines of content

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

The above is the usage of the head command under Linux. The head command can only be used to view the contents of the previous part, not for viewing. Place The contents of the line, you learn it?

Copyright © Windows knowledge All Rights Reserved