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

The method of viewing linux files

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Today, what the editor shares with you is the method of viewing linux files. I believe many people don't know much about it. In order to make you understand better, I summarized the following contents for you. Let's look down together. I'm sure you'll get something.

How to view linux files

Commands to view the contents of the file:

Cat displays the content from the first line and outputs all the content

Tac displays the content in reverse order from the last line and outputs all the content

More according to the window size, page by page of the actual file content

Less is similar to more, but it has the advantage of turning pages forward and searching for characters.

Head displays only the first few lines

Tail displays only the last few lines

Nl is similar to cat-n and outputs the line number when displayed.

Tailf is similar to tail-f

1.cat and tac

The function of cat is to output the contents of the file continuously on the screen starting from the first line. When the file is large, the number of lines is relatively large, and the screen cannot hold all of it, only part of the content can be seen.

Cat syntax: cat [- n] file name (- n: when displayed, line numbers are output together)

The function of tac is to reverse the file from the last line and output the content data to the screen. We can find that tac is actually written backwards by cat.

Tac syntax: tac file name.

2.more and less (commonly used)

The function of more is to start the file from the first line and output the file contents appropriately according to the size of the output window. When a page cannot be fully output, you can use the enter key to flip down the line and the space bar to turn the page down. To exit the view page, press the "Q" key. In addition, more can also be used with the pipe character "|" (pipe), for example: ls-al | more

Syntax for more: more file name

Enter goes down n lines and needs to be defined. The default is 1 line.

Ctrl f scrolls down one screen

The space bar scrolls down one screen

Ctrl b returns to the previous screen

= output the line number of the current line

: F output file name and line number of the current line

V call the vi editor

! Command invokes Shell and executes the command

Q exit more

The function of less is similar to that of more, but you can't turn the page forward with more, only backward.

Less can use the [pageup] and [pagedown] keys for forward and backward page flipping, which looks more convenient.

Syntax for less: less file name

Less also has a feature that allows you to search for what you are looking for in a file. Suppose you want to find a weblogic string in a passwd file, then you can do this:

[root@redhat etc] # less passwd

Then enter:

/ weblogic

Enter

At this point, if there is a weblogic string, linux will highlight the character.

To exit the view page, press the "Q" key.

3.head and tail

Head and tail are usually used when you only need to read the first few lines or the next few lines of the file. The function of head is to display the first few lines of a file

Syntax for head: head [n number] file name (number shows the number of lines)

Tail is just the opposite of head, showing only the last few lines

Syntax of tail: tail [- n number] file name

4.nl

The function of nl is the same as cat-n, which outputs all the contents from the first line and displays the line number.

Syntax for nl: nl file name

5.tailf

The tailf command is almost equivalent to tail-f, and strictly speaking should be more similar to tail-- follow=name. It can also continue to trace when the file is renamed, which is especially suitable for log file tracking (follow the growth of a log file).

Unlike tail-f, if the file does not grow, it will not access the disk file.

Tailf is especially suitable for tracking log files on laptops because it saves power and reduces disk access.

The tailf command is not a script, but a binary execution file compiled in C code, which is not available after some Linux installations.

On the method of viewing linux files to share here, I hope that the above content can have a certain reference value, you can learn to apply. If you like this article, you might as well share it for more people to see.

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