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

Detailed explanation of the command for viewing linux files

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

Share

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

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 to display the content in reverse order from the last line, and to output all the content more according to the window size, the real file content less and more are similar, but its advantages can be turned forward, and the searchable character head displays only the first few lines tail shows only the last few lines nl is similar to cat-n, and the output line number tailf is similar to tail-f when displayed.

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

More syntax: more file name Enter goes down n lines, needs to be defined, defaults to 1 line; Ctrl f scrolls down one screen; spacebar scrolls down one screen; Ctrl b returns the previous screen; = outputs the current line number;: F outputs the file name and current line number; v calls the vi editor;! Command invokes Shell and executes the command; Q exits 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.

The above is all the relevant knowledge points of this introduction, thank you for your study and support.

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