In Linux, you can use the head command to view the first few lines of the file. This command is used to view the contents of the beginning of the file. When the command parameter is set to "-n", you can set the display of the beginning of the file. The number of lines, the syntax is "head -n line number file name".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
How to view the first few lines of a file in Linux
The head command can be used to view the contents of the beginning of the file. There is a commonly used parameter -n Used to display the number of lines, the default is 10, that is, 10 lines of content are displayed.
Command format:
head [参数] [文件]
Parameters:
-q Hide file name
-v Display Filename
-c
-n
Example
To display the first 10 lines of the runoob_notes.log file, enter the following command:
head runoob_notes.log
Display the first 5 lines of the notes.log file OK, please enter the following command:
head -n 5 runoob_notes.log
Display the first 20 bytes of the file:
head -c 20 runoob_notes.log
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of How to view the first few lines of a file in Linux. For more information, please follow other related articles on the PHP Chinese website!