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 to view the contents of files under Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to view file contents under Linux". The content is simple and easy to understand and organized. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "how to view file contents under Linux".

There are many ways to view file content under Linux, you can use: cat, tac, nl, more and other commands.

cat

Display file contents starting with the first line

Grammar:

cat [-AbEnTv]

Options and parameters:

-A: Integration option equivalent to-vET, can list some special characters instead of blank; -b: List line numbers, only for non-blank lines to display line numbers, blank lines do not label line numbers! -E: Display the line break byte $at the end; -n: Print the line number, along with the blank line, which is different from the option of-b; -T: Display the [tab] key as ^I; -v: List some special characters that cannot be seen Check the contents of/etc/issue:

[root@www ~]# cat /etc/issueCentOS release 6.4 (Final)Kernel \r on an \mtac

tac and cat command is just the opposite, the file content from the last line began to display, you can see that tac is cat upside down! For example:

[root@www ~]# tac /etc/issueKernel \r on an \mCentOS release 6.4 (Final)nl

displays line numbers

Grammar:

nl [-bnw] file

Options and parameters:

-b : There are two main ways to specify line numbers: -b a: indicates that line numbers are listed regardless of whether they are blank lines or not (Similar to cat -n); -b t: If there is an empty line, the empty line does not list the line number (default); -n: List the line number representation, there are three main ways: -n ln: Line number is displayed on the far left of the screen; -n rn: Line number is displayed on the far right of its own field, and 0 is not added; -n rz: Line number is displayed on the far right of its own field, and 0 is added; -w: Number of digits occupied by the row number field. Example 1: List the contents of/etc/issue with nl

[root@www ~]# nl /etc/issue 1 CentOS release 6.4 (Final) 2 Kernel \r on an \mmore

Page by page.

[root@www ~]# more /etc/man_db.config## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d.... (middle omitted)... -- More--(28%)

During the run of the more program, you have several buttons to press:

Space: means to scroll down one page; Enter: means to scroll down "one line"; /String: means to search down the keyword "string" in the displayed content; :f: immediately display the file name and the number of lines currently displayed; q: means to immediately leave more, no longer display the content of the file. b or [ctrl]-b: stands for turning back pages, but this action is only useful for files, not pipelines.

less

Page by page, the following example prints the contents of the/etc/man.config file:

[root@www ~]# less /etc/man.config## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d.... (middle omitted)...:

The commands you can enter when running less are:

Blank key: scroll down one page; [pagedown]: scroll down one page; [pageup]: scroll up one page; /string: search down for "string" function; ? string: function to search upward for "string"; n: repeat previous search (and/or? Related!) N: Repeat the previous search in reverse (and/or?) Related!) Q: Leave less of this program;

head

Take out the first few lines of the file

Grammar:

head [-n number] file

Options and parameters:

-n: followed by a number representing the number of lines displayed

[root@www ~]# head /etc/man.config

By default, the first 10 lines are displayed! To display the first 20 lines, you need to do this:

[root@www ~]# head -n 20 /etc/man.configtail

Take out the last few lines of the file

Grammar:

tail [-n number] file

Options and parameters:

-n: followed by a number, representing the meaning of displaying a few lines-f: means to continue detecting the file name followed, and wait until [ctrl]-c to end the tail detection

[root@www ~]# tail /etc/man.config#By default, the last ten lines are displayed! To display the last 20 lines, you'd have to do something like this: [root@www ~]# tail -n 20 /etc/man.config.

The above is "How to view file content under Linux" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

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

Development

Wechat

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

12
Report