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