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