Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How linux reads the first few lines of a file

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge of how linux reads the first few lines of the file. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

In linux, you can use the head command to read the first few lines of the file, which can be used to view the contents of the first few lines of the specified file, with the syntax of "head [- n K] file name"; "K" represents the number of lines, indicating that the contents of the first K line of the file are displayed; if you use "- K", it shows all the remaining contents except the last K line of the file.

The operating environment of this tutorial: CentOS 6 system, Dell G3 computer.

In linux, you can use the head command to read the first few lines of a file.

The head command can be used to view the contents of the beginning of a file. A common parameter,-n, is used to display the number of lines. The default is 10, that is, 10 lines.

The basic syntax format for reading the first few lines of the file is as follows:

Head [- n K] file name

Description:

K represents the number of lines. This option is used to display the contents of the first K line of the file.

If you use "- K" as a parameter, it means that all the remaining contents are displayed except for the last K line of the file.

If K is omitted, 10 lines are displayed by default.

Head command other two commonly used options and meaning option meaning-c K where K represents the number of bytes, this option is used to display the contents of the first K bytes of the file; if you use "- K", it shows all the rest except the last K bytes of the file. -v displays the file name

An example of reading the first few lines of a file:

Specify the number of rows

[root@xuexi ~] # head-n 2 / etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologin

Specifies that all except N lines are displayed at the end.

[root@xuexi] # head-n-40 / etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin

Always show the title file name

[root@xuexi] # head-n 2-v / etc/passwd== > / etc/passwd / etc/passwd / etc/firewalld/firewalld.conf

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report