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

CentOS learning notes from the heart part 5: file content viewing command cat,

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

Share

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

Cat displays the contents of the file from the first line

Tac shows from the last line, you can see that tac is written backwards for cat.

When nl is displayed, and output the line number

More displays the contents of the file page by page

Less is similar to more, but better than more, you can turn the page forward.

Head displays only the first few lines of the file content

Tail displays only a few lines after the contents of the file

Od displays the contents of the file in binary and other ways

1. Cat command

Cat [- AbEnTv] file name

Options and parameters:

-A: the equivalent of-vET's integration option, which lists some special characters instead of white space

-b: list line numbers. Line numbers are displayed only for non-blank lines. Blank lines are not marked with line numbers.

-E: displays the line break character $at the end

-n: print the line number, along with a blank line, which is different from the option of-b

-T: display the [tab] button as ^ I

-v: list some unrecognizable special characters

Example: cat-An / etc/man_db.conf

(man_db.conf is the user's manual configuration file)

By default, cat will display all the contents of the file at once, and when the number of lines of the file exceeds the display screen, the user may not have time to see the results on the screen.

II. Tac command

Display the contents of the file in reverse from the end of the file

The following figure shows the difference between the two tac cat commands that display the contents of the file.

3. Nl command

Format: nl [- bnw] file

Options and parameters:

-b: there are two main ways to specify a line number:

-b a: indicates that the line number is also listed regardless of whether it is blank or not (similar to cat-n)

-b t: if there is a blank line, do not list the line number on the blank line (default)

-n: there are three main ways to list the line number representation:

-n ln: the line number is displayed on the leftmost side of the screen

-n rn: the line number is displayed on the far right of its own field without adding 0

-n rz: the line number is displayed on the far right of its own field, plus 0

-w: the number of characters occupied by the line number field.

The difference between-b an and-b t

The difference of-n ln,-n rn,-n rz

Page flip to view file contents command

IV. More

More / etc/man_db.conf

Space bar: represents turning down one page

Enter: stands for turning down "one line"

/ string: indicates that in this display, look down for the keyword "string"

: F: immediately show the file name and the number of lines currently displayed

Q: the representative immediately leaves the more and no longer displays the contents of the file.

B or [ctrl]-b: means to turn the page back, but this action is only useful for files.

But more cannot turn the page forward.

5. Less command

In more, we have no way to turn forward, we can only look back, but if we use less, hehe! You can use the function of buttons such as [pageup] [pagedown] to go back and forth and browse the file.

In addition, there are more "search" functions in less! You can look not only downwards, but also upwards.

The instructions that can be entered are:

Blank key: turn down one page

[pagedown]: turn a page down

[pageup]: turn a page up

/ string: the function of searching down for "string"

? String: the function of searching up for "string"

N: repeat the previous search (and / or? It's about! )

N: reverse repetition of the previous search (and / or? It's about! )

G: proceed to the first line of this data

G: go to the last line of this data (pay attention to case)

Q: leave the less program

In fact, less also has many functions. For more information on how to use it, please use man less to query it.

VI. Head

Format: head [- n lines] file name

10 lines are displayed by default

When the data followed by-n is negative, it shows the record from the first row to the sum of the total number of records and the data received by the parameter-n. Assuming that / etc/passwd has 54 rows of data, execute head-n-40 / etc/passwd, and the system will display the contents from the first record to the 14th record (54-40 records 14).

7 、 tail

Display the contents of the next few lines

Format: tail [- n lines] file name (positive lines are the same as negative lines)

Tail-f file name: continuously displays the contents of the file and waits until Ctrl+C to terminate the end command

Because / var/log/messages can be written at any time, if you want the file to be displayed on the screen as soon as it is written, use the option-f, the system can always detect the file / var/log/messages, and the newly added data will be displayed on the screen until the user presses [crtl]-c to leave the tail command operation! Because the messages must have root permission to see it, the example has to be queried using root.

How do I display the contents of lines 11 to 20 of / etc/passwd?

A: this is easy to implement. You can take the first 20 lines and then the last 10 lines, so the result is "head-n 20 / etc/passwd | tail-n 10", so you can get the content between lines 11 and 20.

8 、 od

Display the contents of the file in binary, etc.

Format: od [- t TYPE] file

-t: various "TYPE" outputs can be followed by, for example:

A: use default characters to output

C: use ASCII characters to output

D [size]: use decimal (decimal) to output data, each integer occupies size Bytes

F [size]: use floating point values (floating) to output data, each number occupies size Bytes

O [size]: use octal (octal) to output data, each integer occupies size Bytes

X [size]: use hexadecimal (hexadecimal) to output data, each integer occupies size Bytes

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