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?
The sound menu in Ubuntu system is unique. The sound of all applications can be adj
Many users who like to use the chmod command are still not very clear about the mea
In the Gnome graphical desktop environment of Ubuntu system, some users have encoun
Linux system command startx function is very simple, is to start the X Window service, there is noth
How to use commands to manage files in Linux
How to use the Linux system Passwd command
Linux system apachectl command instructions
What should I do if the Fedora 18 DNSenum shows IP garbled?
Linux system XF86Setup command syntax and use parameters
View the Linux version of the skill
What should I do if the U disk file is read-only on Ubuntu and cannot be deleted?
How to check the version of Shell that Linux system is using?
When prompted to start the vi editor in Linux, prompt E325: What should ATTENTION do?
Parameters and function descriptions of the Linux system Xconfigurator command
Turn off Windows 7 Edge Auto Maximization Method
The meaning of the computer startup failure prompts
Xvidcore.dll not found what to do xvidcore.dll error solution
Analysis: MED-V(2) of IE virtualization under Windows7
Win10 update 1511 (TH2 official version) version of the blue screen solution
Four steps to securely protect servers on the cloud
What should I do if the winXP host has no sound in the front of the headset?