Head and tail are as simple as their name, which is used to display the beginning or end of a 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, and 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-012014-022014-032014-042014-052014-062014-072014-082014-092014-102014-112014-12=========================== ===[[email protected] test]# head-n 5 log2014.log 2014-012014-022014-032014-042014-05[[email protected] test]#
Example 2: Displaying the first n bytes of a file
Command :
Head-c Log2014.log
Output :
[Email protected] test]# Head-c-32 Log2014.log2014-012014-022014-032014-042014-052014-062014-072014-082014-092014-102014-112014-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.log2014-012014-022014-032014-042014-052014-062014-07[[email protected] Calhost test]#
Add
Command parameters:
-c< bytes > Display bytes
Display units: Line
Ps:
When you calculate a character, the newline character takes up two bytes.
And at the end of each line there is an end character that does not appear to occupy one byte. (If there is a newline character, it is treated as an end, accounting for two bytes.) )
You can use WC-C filename to view the number of characters
One Linux command per day: Head command