Home  >  Article  >  Operation and Maintenance  >  How to view the first few lines of a file in Linux

How to view the first few lines of a file in Linux

WBOY
WBOYOriginal
2022-01-04 10:00:0317598browse

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".

How to view the first few lines of a file in Linux

#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

  • -cc8f01a3f8889dcf657849dd45bc0fc4c The number of bytes displayed.

  • -n5229c5cf874adab03db92291906957a1 The number of rows to display.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn