More and less command usage in Linux

Source: Internet
Author: User

One,more commands, similar to cat, the Cat command is the entire contents of the file displayed on the screen from top to bottom. More will be a page-by-page display to facilitate users to read pages, and the most basic instruction is to press the blank key (space) on the next page, press the B key will be back to a page, but also the function of the search string. The more command reads the file backwards from the front, so it loads the entire file at startup.

1. Command format:

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

2. Command function:

The more commands and the cat function are the same view of the contents of the file, but the difference is that more can be viewed by the page to view the contents of the file, but also support the function of direct jump.

3. Command parameters:

+n starting from joys N rows

-N defines the screen size as n rows

+/pattern searches for the string before each file is displayed, and then starts from the first two lines of the string

-C clear the screen from the top and then display

-D hint "press space to continue, ' Q ' To quit (press SPACEBAR to continue, pressing Q key to exit)", disable the ringing function

-L ignores Ctrl+l (page break) characters

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

-S displays a contiguous number of empty rows as a row

-U Remove the line from the contents of the file

4. Common Operation Commands:

Enter down n rows, which need to be defined. Default is 1 rows

CTRL+F Scroll down one screen

Space bar scroll down one screen

Ctrl+b Back to previous screen

= Output the line number of the current line

: F output File name and line number of the current line

V Call VI Editor

command to invoke the shell and execute the command

Q Exit More

5. Command instance:

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

Command:

Cat Test.log #显示所有日志内容
[Email protected]:~/alm$ more +3 test.log #从第三行开始显示日志内容

Output:

1[Email protected]:~/alm$CatTest.log2  .-8-1Aijian.shi3  .-8-2Yafang.wei4  .-8-3Hong.zhan5  .-8-4Yuyan.zhang6  .-8-5Senlin.zhao7  .-8-6Yanbin.liu8  .-8-7Hui.liu9  .-8-8Yanhua.liuTen  .-8-9Baoixn.cui One  .-8-TenGe.song A  .-8- OneZhongjun.zhen -  .-8- AQiu.liao
[Email protected]:~/alm$ more +3 Test.log
2016-8-3 Hong.zhan
2016-8-4 Yuyan.zhang
2016-8-5 Senlin.zhao
2016-8-6 Yanbin.liu
2016-8-7 Hui.liu
2016-8-8 Yanhua.liu
2016-8-9 Baoixn.cui
2016-8-10 Ge.song
2016-8-11 Zhongjun.zhen
2016-8-12 Qiu.lia

Example 2. Set the log content to display 4 rows per screen

Command:

 More-4 Test.log

Output:

1[Email protected]:~/alm$ More-4Test.log2  .-8-1Aijian.shi3  .-8-2Yafang.wei4  .-8-3Hong.zhan5  .-8-4Yuyan.zhang6 7 skipping one line #这里使用ctrl +f or SPACEBAR to scroll the screen8  .-8-6Yanbin.liu9  .-8-7Hui.liuTen  .-8-8Yanhua.liu One  .-8-9Baoixn.cui A  - ... .. skipping one line -  .-8- OneZhongjun.zhen the  .-8- AQiu.liao

Instance 3. Find the first occurrence of "liu The line of the string, and the first two lines from there display the output

Command:

 more +/liu Test.log

Output:

1[Email protected]:~/alm$ More+/Liu Test.log2 3 . .. skipping4  .-8-4Yuyan.zhang5  .-8-5Senlin.zhao6  .-8-6Yanbin.liu7  .-8-7Hui.liu8  .-8-8Yanhua.liu9  .-8-9Baoixn.cuiTen  .-8-TenGe.song One  .-8- OneZhongjun.zhen A  .-8- AQiu.liao

Example 4. When there are too many files in a directory, you can display them in more detail. This has to do with plumbing | Combined.

Command:

Cat  More-5 # "|" Represents a pipeline in which the output of the preceding command can be used as input to a subsequent command

Output:

1[Email protected]:~/alm$CatTest.log | More-52  .-8-1Aijian.shi3  .-8-2Yafang.wei4  .-8-3Hong.zhan5  .-8-4Yuyan.zhang6  .-8-5Senlin.zhao7 8 ... .. skipping one line9  .-8-7Hui.liuTen  .-8-8Yanhua.liu One  .-8-9Baoixn.cui A  .-8-TenGe.song -  .-8- OneZhongjun.zhen --- More--

Two

The less tool is also a tool for paging through files or other output, which is a very powerful tool for Linux to view the contents of a file. The usage of less is more resilient than more. In more, we have no way to turn front, can only look back, but if use less, you can use [PageUp] [PageDown] and other key functions to go to look at the file, more easily used to view the contents of a file! In addition, in less you can have more search function, not only to search down, but also to search upward.

1. Command format:

Less [parameter] file

2. Command function:

Less is similar to more, but you can browse files at will with less, and more can only move forward, but not backwards, and no will load the entire file before viewing it.

3. Command parameters:

-B < buffer size > Set buffer size

-e When the file display is finished, automatically leave

-F forcing special files to be opened, such as peripheral code, directories, and binaries

-G only flags the last keyword searched

-I ignores case when searching

-m shows a percentage similar to the more command

-N Displays the line number of each line

-o < file name > save less output in the specified file

-Q does not use warning tones

-S displays a row of continuous empty behavior

-S line too long will be out of the partial discard

-X < number > Displays the "tab" key as a specified number space

/string: Search down the function of "string"

String: The ability to search up "string"

N: Repeat the previous search (with/or?). About

N: Reverse repeats the previous search (and/or?) About

b Turn back one page

D Turn back half a page

H Display Help interface

Q Exit less command

U scroll forward Half page

Y Scrolls forward one line

SPACEBAR Scrolls one line

Enter key to scroll one page

[PageDown]: Flip one PAGE Down

[PageUp]: Flip one page Up

More and less command usage in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.