[Linux learning] View file content

Linux file content viewing

When using the Linux system, it is often necessary to view some files, and Linux provides us with a command to view the contents of the files. This article summarizes it.

1、cat/tac/nl

1.1 cat

Format: cat -AbEnTv filename

Print the entire file to the screen from the first line of the file to the end.

-A : Display special characters in the file

-b : display line numbers for non-blank lines

-E : Display end-of-line terminators

-n : Display line numbers of all lines, including blank lines

-T : Display the blank character of the [ Tab key] with ^I

-v : show some invisible other special symbols

1.2 tac

Format: tac -AbEnTv filename

Prints the entire file to the screen in order from the last line of the file to the first. The options for the command are the same as for the cat command.

1.3 nl

Format: nl -bnw filename

This command is mainly used to add line numbers to a file and print to the screen.

-b

-ba : add line numbers to blank lines in the file

-bt : Blank lines in file do not add line numbers

-n

-n ln : the line number is on the left side of the line

-n rn : the line number is to the right of the line number column, do not add ' 0 '

-n rz : The line number is to the right of the line number column, and ' 0 ' is added. For example , 0001 , 0002 , etc.

-w

-w [ number ] : Set the number of significant digits of the line number, including padded ' 0 '

2、more/less

2.1 more

View files in the way of [Page Turning] and support the following operations:

Next page: Press [Spacebar] directly

Next line: directly press [ Entere key]

Search string: directly press [ / ], then press the corresponding string to be searched

Display the number of files and lines: enter [ :f ]

Stop viewing files: press [ q ] between

Page back: press【 b

2.2 tail

View files in the way of [Page Turning] and support the following operations:

Next page: Press【Spacebar】or【 pagedown

Previous page: 【 pageup

Search down the string: press [ / ]

Look up a string: press [?

Next found string: press【 n

Last found string: Press【 N

Exit viewing: press【 q

3head/tail

3.1head

Format: head [-n number ] file

View the front part of the file. If the -n option is not specified, the first 10 lines of the file are viewed by default . This command also supports sliced ​​viewing. For example, if you do not want to view the last 100 lines of the file, you can specify the command head -n -100 a.txt , and only the rest of the a.txt file except the last 100 lines will be displayed .

3.2tail

Format: tail [-n number ] file

View the content of the latter part of the file. If the -n option is not specified, the content of the last 10 lines of the file will be viewed by default . This command also supports sliced ​​viewing. For example, if you do not want to view the first 100 lines of the file, you can specify the command tail -n +100 a.txt , then only the rest of the a.txt file except the first 100 lines will be displayed.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325733948&siteId=291194637