Linux basics-3day-Linux document operation command-(cat/more/less/head/tail)

Linu X document operation command - ( CAT / More / less / head / tail )

1. The cat command

Description: View file content; file creation; file merge. It is often used to display the content of a file, or connect several files to display, or read the content from standard input and display it. It is often used in conjunction with the redirection symbol.

Usage: cat [parameter options] [file name] 

parameter:

parameter

significance

-b

Display line number, blank cell does not display

-n

Display the line number, also display blank cells

-E

Display $ at the end of each line

-s

If there are more than two consecutive blank lines, replace them with one blank line

-T

--show-tabs displays tab characters as ^I

Eg1 :

[root@test ~]#cat -n ping.sh test.txt #Add a line number to display the contents of two files 
[root@test ~]#cat ping.sh test.txt >test1.txt #Merge two files into one 
[root@test ~]#cat> test2.txt #Create file text2.txt and write

2. More command

Description: View the content of the file by page, view the next page by space bar, and q to exit.

Usage: more [parameter options] [file name]

parameter:

parameter

significance

+n

Display from line n

-n

Define the screen size as n lines

-c/-p

Clear the screen from the top, and page the file by clearing the window instead of scrolling

-s

Multiple blank lines will be displayed as one line

-u

Remove the underscore from the content of the file

+/pattern

Search for the pattern before each file is displayed, and then start displaying after the first two lines of the string  

Common operation commands:

action

significance

Enter

Down n lines, need to be defined, the default is 1 line

Ctrl+F

Scroll down one screen

Ctrl+B

Scroll up one screen

=

Output current line number

v

Call vi edit

:f

Display current file name and current line number

!command

Execute shell commands

q

drop out

3. Less command

Description: View file content in pages.

Usage: less [parameter options] [file name]

parameter:

parameter

Features

-e

After the file is displayed, it will exit automatically

-f

Force opening of special files, such as directories, binary files, etc.

-g

Only mark the last searched keyword

-i

Ignore case when searching

-m

Show the percentage of commands like more

-o <file name>

Save the content output by less in the specified file

-Q

Not applicable warning sound

-s

Show continuous empty rows

-S

When the line is too long, discard the extra part

-x<number>

Display the "tab" key value as a number space

/String

Search string down

?String

Search string up

Common operations:

action

Features

n

Repeat the previous search

N

Repeat the previous search in reverse

b

Page backward

d

Page forward

h

Show help interface

q

Exit the less command

u

Scroll forward half a page

and

Scroll forward one line

Space

Scroll one line

Carriage return

Scroll one page

pgup

Page up

pgdown

Page down

4. The head command

Description: View the content of the file header, the first 10 lines are displayed by default

Usage: head [parameter options] [file name]

parameter:

-q

Hide file name

-v

Show file name

-n<number of lines>

Display line number

-c<byte>

Display the number of bytes

Eg1:

[root@test ~]# head -n test #Display the first 20 lines of the file test

5. Tail command

描述:查看文件尾部内容,默认显示10行。

用法:tail  [参数选项] [文件名程]

参数:

-n

显示文件末尾n行内容

-f

动态显示文件内容,常用于查看实时日志信息

--pid=PID

 与-f合用,表示在进程ID,PID死掉之后结束.

Eg:

[root@test ~]# tail -n 20 test     #显示test文件后20行

个人公众号:

图片.png

 

 

 


Guess you like

Origin blog.51cto.com/13440764/2576733