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

How to display the last few lines of a file in Linux

青灯夜游
青灯夜游Original
2023-03-10 18:56:2112767browse

In Linux, you can use the tail command to display the last few lines of the file. The tail command is used to display the last few lines of the file to the standard output. By default, the tail command prints the last 10 lines of the corresponding file; the syntax is "tail [options] file name". If the parameter options is omitted, the last 10 lines of the file will be displayed. If options Setting it to "-n number of lines" will display the content of the last specified number of lines.

How to display the last few lines of a file in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

In Linux, you can use the tail command to display the last few lines of the file.

Linux tail command

The tail command in Linux is used to display the last few lines of the file to the standard output. The default tail The command prints the last 10 lines of its corresponding file, and its effect is exactly the opposite of the head command.

Syntax:

tail [options] file..

Parameters:

Parameters Description
options Parameters used by the tail command.
file The file name to be viewed.

tail command common options parameters

Parameters Description
-n K The K here refers to the number of lines. This option means to output the last K lines. On this basis, if you use -n K means to start outputting from the Kth line of the file.
-c K The K here refers to the number of bytes. This option indicates the content of the last K bytes of the output file. On this basis, use -c K means starting output from the Kth byte of the file.
-f Output the newly added data after the file changes.
-q Does not display processing information.

Common examples of Linux tail command

Example 1. View /etc/vimrc File content

tail /etc/vimrc

After running, the terminal output is as follows:

How to display the last few lines of a file in Linux

We see that we used the tail command to view the file content. By default The last ten lines are shown.

Example 2: View the last few lines of the file

tail -n 2 /etc/vimrc

How to display the last few lines of a file in Linux

We see that we used the tail command to view only the last two lines of the file .

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to display the last 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