More and less command usage in Linux

Source: Internet
Author: User

Tag: config copy time exceeds 0.12 duplicate TTY log init

One, more commands

More features like 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:

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

Output:

1 [Email protected]:~/alm$ cat Test.log 2 2016-8-1 Aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 Hong.zhan 5 2016-8-4 Yuyan. Zhang 6 2016-8-5 senlin.zhao 7 2016-8-6 yanbin.liu 8 2016-8-7 hui.liu 9 2016-8-8 yanhua.liu10 2016-8-9 baoixn.cui11 2016-8 -10 ge.song12 2016-8-11 zhongjun.zhen13 2016-8-12 Qiu.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:

[Email protected]:~/alm$ more-4 Test.log

Output:

1 [Email protected]:~/alm$ more-4 test.log 2 2016-8-1 Aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 hong.zhan 5 2016-8-4 Yu Yan.zhang 6  7 ... skipping one line #这里使用ctrl +f or SPACEBAR to roll the screen 8 2016-8-6 Yanbin.liu 9 2016-8-7 hui.liu10 2016-8- 8 Yanhua.liu11 2016-8-9 baoixn.cui12 ... skipping one line14 2016-8-11 zhongjun.zhen15 2016-8-12 Qiu.liao

Example 3. Find the first line in a file that appears with a "Liu" string and start displaying the output from the first two lines

Command:

[Email protected]:~/alm$ more +/liu Test.log

Output:

1 [Email protected]:~/alm$ more +/liu test.log 2  3 ... skipping 4 2016-8-4 Yuyan.zhang 5 2016-8-5 Senlin.zhao 6 2016-8- 6 Yanbin.liu 7 2016-8-7 Hui.liu 8 2016-8-8 yanhua.liu 9 2016-8-9 baoixn.cui10 2016-8-10 ge.song11 2016-8-11 zhongjun.zhen1 2 2016-8-12 Qiu.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:

[Email protected]:~/alm$ cat Test.log | 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$ cat Test.log | More-5 2 2016-8-1 Aijian.shi 3 2016-8-2 yafang.wei 4 2016-8-3 Hong.zhan 5 2016-8-4 Yuyan.zhang 6 2016-8-5 Senlin.zhao 7
   8 Skipping one line 9 2016-8-7 hui.liu10 2016-8-8 yanhua.liu11 2016-8-9 baoixn.cui12 2016-8-10 ge.song13 2016-8-11 Z Hongjun.zhen14--more--

Second, less directives

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

4. Usage examples:

Instance 1:ps viewing process information and displaying line numbers simultaneously with less paging

Command:

[Email protected]:~/alm$ ps-ef|less-n

Output:

 1 1 UID PID PPID C stime TTY time CMD 2 2 root 1 0 0 Aug08?        00:00:00/sbin/init 3 3 root 2 0 0 Aug08?        00:00:00 [Kthreadd] 4 4 root 3 2 0 Aug08?        00:00:02 [ksoftirqd/0] 5 5 root 6 2 0 Aug08?        00:00:00 [migration/0] 6 6 Root 7 2 0 Aug08?        00:00:00 [watchdog/0] 7 7 root 8 2 0 Aug08?        00:00:00 [MIGRATION/1] 8 8 root 9 2 0 Aug08?        00:00:00 [kworker/1:0] 9 9 root 2 0 Aug08?        00:00:01 [ksoftirqd/1]10 root 2 0 Aug08?        00:00:00 [watchdog/1]11 root 2 0 Aug08?        00:00:00 [migration/2]12 root 2 0 Aug08?        00:00:01 [ksoftirqd/2]13 root 2 0 Aug08?        00:00:00 [watchdog/2]14 root 2 0 Aug08? 00:00:00 [migration/3]15 15Root 2 0 Aug08?        00:00:01 [ksoftirqd/3]16 root 2 0 Aug08?        00:00:00 [watchdog/3]17-root 2 0 Aug08?        00:00:00 [migration/4]18 root 2 0 Aug08?        00:00:00 [ksoftirqd/4]19 root 2 0 Aug08?        00:00:00 [watchdog/4]20 root 2 0 Aug08?        00:00:00 [migration/5]21 root 2 0 Aug08?        00:00:00 [ksoftirqd/5]22 root 2 0 Aug08?        00:00:00 [watchdog/5]23 2 0 Aug08? 00:00:00 [migration/6]24:

Example 2. Browse Multiple Files

Command:

[Email protected]:~/alm$ less Test2.log test.log

Output:

1     1  ifconfig 2     2  ping www.baidu.com 3     3  ifconfig 4     4  //10.128.161.108/share 5     5  10.128.161.108/share 6     6  SSH 7     7  keygen 8     8  TRSA 9     9  ssh10    10  . SSH/11  Test2.log (file 1 of 2) (END)-Next:test.log

Description

Input: N, switch to Test.log

Enter: p, switch to Test2.log

PS: When you are browsing a file, you can also use the: E command to open another file.

Command:

Less file1:e file2

5. Additional Notes

1. Full Screen navigation

CTRL + F-Move forward one screen

CTRL + B-Move backward one screen

CTRL + D-Move forward half screen

CTRL + U-Move backward half screen

2. Single-line navigation

J-Move one line forward

K-Move backward one line

3. Other navigation

G-Move to the last line

G-Move to the first line

Q/zz-Exit less command

4. Other useful commands

V-Edit the current file using the configured editor

H-Show help documentation for less

&pattern-Displays only the lines of the matching pattern, not the entire file

5. Tag Navigation

When you use less to view large files, you can mark them in any one place, and you can navigate to the text location labeled with a specific tag by command:

Ma-Use A to mark the current position of the text

' A-navigate to mark a

6. Find

More, less has the Find function, press/then enter the string to be searched, press ENTER again, press N (next) will continue to find, uppercase N is back (up) to find, press Q (quit) or ZZ leave

Transferred from: http://www.cnblogs.com/aijianshi/p/5750911.html

More and less command usage in Linux (RPM)

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.