Home > Operation and Maintenance > Linux 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
Release: 2022-01-04 10:00:03
Original
17640 people have browsed it

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 [参数] [文件]
Copy after login

Parameters:

  • -q Hide file name

  • -v Display Filename

  • -c The number of bytes displayed.

  • -n 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
Copy after login

Display the first 5 lines of the notes.log file OK, please enter the following command:

head -n 5 runoob_notes.log
Copy after login

Display the first 20 bytes of the file:

head -c 20 runoob_notes.log
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template