head and tail are as simple as their name, which is used to display the beginning or end of a certain number of chunks of text, the head is used to display the beginning of the file to the standard output, and tail to see the end of the file .
1. command format:
head [ parameters ] ... [ file ] ...
2. Command function:
the 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 names
-V Show file name
-c< bytes > Display bytes
-n< rows > rows displayed
4. usage Examples:
Example 1: Display the first n rows of a file
Command:
Head-n 5 Log2014.log
Output:
[[email protected] 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 Log2014.log
Output:
[[email protected] test] # head-c Log2014.log
2014-01
2014-02
2014
[[email protected] test] #
Example 3: the file except the last N bytes Outside of the content
Command:
Head-c- 3 2 log201 4 . Log
Output:
[[email protected] 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[[email protected] test] #
Example 4: Output file except the last n rows of the entire content
Command:
Head-n-6 Log2014.log
Output:
[[email protected] test] # Head-n-6 Log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07 [root@localhost test] #
This article is from the Linux Security Advisor blog, so be sure to keep this source http://chengyangyang.blog.51cto.com/9473151/1680889
One Linux command per day: Head command