Linux common commands: more command

  The more command is similar in function to cat. The cat command displays the contents of the entire file on the screen from top to bottom. more will be displayed page by page for users to read page by page, and the most basic command is to press the space key (space) to display the next page, and press the b key to display one page back, and There is also a search string function. The more command reads the file from front to back, so the entire file is loaded at startup.

1. Command format:

more [-dlfpcsu ] [-num ] [+/ pattern] [+ linenum] [file ... ] 

2. Command function:

  The more command has the same function as cat to view the contents of the file, but the difference is that more can view the contents of the file by page, and also supports functions such as direct jumping of lines.

3. Command parameters:

+n display from the nth line

-n defines the screen size as n lines

+/pattern searches for the string (pattern) before each file is displayed, then starts displaying after the first two lines of the string  

-c clear the screen from the top, then show

-d prompts "Press space to continue, 'q' to quit (press space to continue, press q to quit)", disable the bell function

-l ignore Ctrl+l (form feed) character

-p page the file by clearing the window instead of scrolling, similar to the -c option

-s Display multiple consecutive blank lines as one line

-u remove the underscore from the file content

4. Common operating commands:

Enter goes down n lines, needs to be defined. Default is 1 line

Ctrl+F Scroll down one screen

Spacebar Scroll down one screen

Ctrl+B Return to the previous screen

= print the line number of the current line

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

V invoke vi editor

!command Invoke the shell and execute the command 

q quit more

5. Command example:

Example 1: Display the contents of the file starting from line 3

Order:

more +3 log2012.log

output:

[root@localhost test]# cat log2012.log 

2012-01

2012-02

2012-03

2012-04-day1

2012 - 04 - day2

2012 - 04 - day3

======[root@localhost test]# more +3 log2012.log 

2012-03

2012-04-day1

2012 - 04 - day2

2012 - 04 - day3

======[root@localhost test]#

 

 

Example 2: Find the first line in the file where the string "day3" appears, and start displaying the output from the first two lines there 

Order:

 more +/day3 log2012.log

output:

[root@localhost test]# more +/day3 log2012.log 

...skipping

2012-04-day1

2012 - 04 - day2

2012 - 04 - day3

2012-05

2012-05-day1

======[root@localhost test]#

 

Example 3: Set the number of lines displayed per screen 

Order:

more -5 log2012.log

output:

[root@localhost test]# more -5 log2012.log 

2012-01

2012-02

2012-03

2012-04-day1

2012 - 04 -day2

 illustrate:

  As shown in the figure below, the bottom part shows the proportion of the content displayed on this screen to the total number of lines in the file. Press Ctrl+F or the space bar to display 5 pieces of content on the next screen, and the percentage will also change accordingly.

 

Example 4: List the files in a directory. Since there are too many contents, we should learn to use more to display them in pagination. This has to be combined with the pipe | 

Order:

ls -l  | more -5

output:

[root@localhost test]#  ls -l  | more -5

total 36

-rw-r--r-- 1 root root  308 11-01 16:49 log2012.log

-rw-r--r-- 1 root root   33 10-28 16:54 log2013.log

-rw-r--r-- 1 root root  127 10-28 16:51 log2014.log

lrwxrwxrwx 1 root root    7 10-28 15:18 log_link.log -> log.log

-rw-r--r-- 1 root root   25 10-28 17:02 log.log

-rw-r--r-- 1 root root   37 10-28 17:07 log.txt

drwxr-xr-x 6 root root 4096 10-27 01:58 scf

drwxrwxrwx 2 root root 4096 10-28 14:47 test3

drwxrwxrwx 2 root root 4096 10-28 14:47 test4

 illustrate:

  Each page displays 5 file information, press Ctrl+F or space bar will display the next 5 file information.

Guess you like

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