How to use the more command in linux

 



    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. Brothers Linux training tutorial (www.lampbrother.net) 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 go to the next page, and press the b key to go to the next page. Will go back (back) one page display, and there is 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 content of the file by page, and also supports functions such as direct jumping of lines.

  3. Command parameters:

  +n start display from the nth line

  -n ​​define the screen size to be n lines

  +/pattern Search for the string (pattern) before each file is displayed, and then start to display from the first two lines of the string

  - c clear the screen from the top, then display

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

  -l ignore Ctrl+l (form feed) characters

  -p Forms the file by clearing the window instead of scrolling, similar to

  the -c option -s Displays multiple consecutive blank lines as one line

  -u Removes the underscore from the file content

  4. Common operation commands:

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

  Ctrl+F Scroll down one screen

  Spacebar Scroll down one screen

  Ctrl+B Return to the previous screen

  = Output the line number of the current line

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

  V Call the vi editor

  ! command Call Shell, and execute command

  q to exit more

  5. Command example:

  Example 1: Display the content of the file from line 3

  Command :

  more +3 log2012.log

  output:

  copy the code The code is as follows:

  [root@localhost test]# cat log2012.log 2012-01

  2012-02

  2012-03

  2012-04

  -day1

  2012-04-day2

  2012-04-day3</p> <p>======[root@localhost test]# more +3 log2012.log

  2012-03

  2012-04-day1

  2012-04-day2

  2012-04-day3</p> <p>======[root@localhost test]#

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

  Command :

  more +/day3 log2012.log

  Output:

  Copy the code The code is as follows:

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

  ...skipping

  2012-04-day1

  2012-04-day2

  2012-04-day3

  2012-05

  2012-05-day1</p> <p>======[ root@localhost test] #Example

  3: Set the number of lines displayed per screen

  Command :

  more -5 log2012.log

  output:

  copy the code The code is as follows:

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

  2012-01

  2012-02

  2012-03

  2012-04-day1

  2012-04-day2

  Description:

  The bottom 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 in the next screen, and the percentage is also will change.

  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 |

  Command :

  ls -l | more -5

  Output:

  Copy the code The code is as follows:

  [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

  Description:

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

Guess you like

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