hankchow translated

This commit is contained in:
HankChow 2018-11-15 15:48:45 +08:00
parent d19a2a1adc
commit 63c3355cd2
2 changed files with 230 additions and 234 deletions

View File

@ -1,234 +0,0 @@
HankChow translating
The Difference Between more, less And most Commands
======
![](https://www.ostechnix.com/wp-content/uploads/2018/11/more-less-and-most-commands-720x340.png)
If youre a newbie Linux user, you might be confused with these three command like utilities, namely **more** , **less** and **most**. No problem! In this brief guide, I will explain the differences between these three commands, with some examples in Linux. To be precise, they are more or less same with slight differences. All these commands comes preinstalled in most Linux distributions.
First, we will discuss about more command.
### The more program
The **more** is an old and basic terminal pager or paging program that is used to open a given file for interactive reading. If the content of the file is too large to fit in one screen, it displays the contents page by page. You can scroll through the contents of the file by pressing **ENTER** or **SPACE BAR** keys. But one limitation is you can scroll in **forward direction only** , not backwards. That means, you can scroll down, but cant go up.
![](https://www.ostechnix.com/wp-content/uploads/2018/11/more-command-demo.gif)
**Update:**
A fellow Linux user has pointed out that more command do allow backward scrolling. The original version allowed only the forward scrolling. However, the newer implementations allows limited backward movement. To scroll backwards, just press **b**. The only limitation is that it doesnt work for pipes (ls|more for example).
To quit, press **q**.
**more command examples:**
Open a file, for example ostechnix.txt, for interactive reading:
```
$ more ostechnix.txt
```
To search for a string, type search query after the forward slash (/) like below:
```
/linux
```
To go to then next matching string, press **n**.
To open the file start at line number 10, simply type:
```
$ more +10 file
```
The above command show the contents of ostechnix.txt starting from 10th line.
If you want the more utility to prompt you to continue reading file by pressing the space bar key, just use **-d** flag:
```
$ more -d ostechnix.txt
```
![][2]
As you see in the above screenshot, the more command prompts you to press SPACE to continue.
To view the summary of all options and keybindings in the help section, press **h**.
For more details about **more** command, refer man pages.
```
$ man more
```
### The less program
The **less** command is also used to open a given file for interactive reading, allowing scrolling and search. If the content of the file is too large, it pages the output and so you can scroll page by page. Unlike the more command, it allows scrolling on both directions. That means, you can scroll up and down through a file.
![](https://www.ostechnix.com/wp-content/uploads/2018/11/less-command-demo.gif)
So, feature-wise, less has more advantages than more command. Here are some notable advantages of less command:
* Allows forward and backward scrolling,
* Search in forward and backward directions,
* Go to the end and start of the file immediately,
* Open the given file in an editor.
**less command examples:**
Open a file:
```
$ less ostechnix.txt
```
Press **SPACE BAR** or **ENTER** key to go down and press **b** to go up.
To perform a forward search, type search query after the forward slash ( **/** ) like below:
```
/linux
```
To go to then next matching string, press **n**. To go back to the previous matching string, press **N** (shift+n).
To perform a backward search, type search query after the question mark ( **?** ) like below:
```
?linux
```
Press **n/N** to go to **next/previous** match.
To open the currently opened file in an editor, press **v**. It will open your file in your default text editor. You can now edit, remove, rename the text in the file.
To view the summary of less commands, options, keybindings, press **h**.
To quit, press **q**.
For more details about less command, refer the man pages.
```
$ man less
```
### The most program
The most terminal pager has more features than more and less programs. Unlike the previous utilities, the most command can able to open more than one file at a time. You can easily switch between the opened files, edit the current file, jump to the **N** th line in the opened file, split the current window in half, lock and scroll windows together and so on. By default, it wont wrap the long lines, but truncates them and provides a left/right scrolling option.
**most command examples:**
Open a single file:
```
$ most ostechnix1.txt
```
![](https://www.ostechnix.com/wp-content/uploads/2018/11/most-command.png)
To edit the current file, press **e**.
To perform a forward search, press **/** or **S** or **f** and type the search query. Press **n** to find the next matching string in the current direction.
![][3]
To perform a backward search, press **?** and type the search query. Similarly, press **n** to find the next matching string in the current direction.
Open multiple files at once:
```
$ most ostechnix1.txt ostechnix2.txt ostechnix3.txt
```
If you have opened multiple files, you can switch to next file by typing **:n**. Use **UP/DOWN** arrow keys to select next file and hit **ENTER** key to view the chosen file.
![](https://www.ostechnix.com/wp-content/uploads/2018/11/most-2.gif)
To open a file at the first occurrence of given string, for example **linux** :
```
$ most file +/linux
```
To view the help section, press **h** at any time.
**List of all keybindings:**
Navigation:
* **SPACE, D** Scroll down one screen.
* **DELETE, U** Scroll Up one screen.
* **DOWN arrow** Move Down one line.
* **UP arrow** Move Up one line.
* **T** Goto Top of File.
* **B** Goto Bottom of file.
* **> , TAB** Scroll Window right.
* **<** Scroll Window left.
* **RIGHT arrow** Scroll Window left by 1 column.
* **LEFT arrow** Scroll Window right by 1 column.
* **J, G** Goto nth line. For example, to jump to the 10th line, simply type **“100j”** (without quotes).
* **%** Goto percent.
Window Commands:
* **Ctrl-X 2, Ctrl-W 2** Split window.
* **Ctrl-X 1, Ctrl-W 1** Make only one window.
* **O, Ctrl-X O** Move to other window.
* **Ctrl-X 0 (zero)** Delete Window.
Search through files:
* **S, f, /** Search forward.
* **?** Search Backward.
* **N** Find next match in current search direction.
Exit:
* **q** Quit MOST program. All opened files will be closed.
* **:N, :n** Quit this file and view next (Use UP/DOWN arrow keys to select next file).
For more details about most command, refer the man pages.
```
$ man most
```
### TL;DR
**more** An old, very basic paging program. Allows only forward navigation and limited backward navigation.
**less** It has more features than more utility. Allows both forward and backward navigation and search functionalities. It starts faster than text editors like **vi** when you open large text files.
**most** It has all features of above programs including additional features, like opening multiple files at a time, locking and scrolling all windows together, splitting the windows and more.
And, thats all for now. Hope you got the basic idea about these three paging programs. Ive covered only the basics. You can learn more advanced options and functionalities of these programs by looking into the respective programs man pages.
More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/the-difference-between-more-less-and-most-commands/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[2]: http://www.ostechnix.com/wp-content/uploads/2018/11/more-1.png
[3]: http://www.ostechnix.com/wp-content/uploads/2018/11/most-1-1.gif

View File

@ -0,0 +1,230 @@
more、less 和 most 的区别
======
![](https://www.ostechnix.com/wp-content/uploads/2018/11/more-less-and-most-commands-720x340.png)
如果你是一个 Linux 方面的新手,你可能会在 `more`、`less`、`most` 这三个命令行工具之间产生疑惑。在本文当中,我会对这三个命令行工具进行对比,以及展示它们各自在 Linux 中的一些使用例子。总的来说,这几个命令行工具之间都有相通和差异,而且它们在大部分 Linux 发行版上都有自带。
我们首先来看看 `more` 命令。
### more 命令
`more` 是一个较为传统的终端阅读工具,它可以用于打开指定的文件并进行交互式阅读。如果文件的内容太长,在一屏以内无法完整显示,就会逐页显示文件内容。使用回车键或者空格键可以滚动浏览文件的内容,但有一个限制,就是只能够单向滚动。也就是说只能按顺序往下翻页,而不能进行回看。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/more-command-demo.gif)
**更新**
有的 Linux 用户向我指出,在 `more` 当中是可以向上翻页的。不过,最原始版本的 `more` 确实只允许向下翻页,在后续出现的较新的版本中也允许了有限次数的向上翻页,只需要在浏览过程中按 `b` 键即可向上翻页。唯一的限制是 `more` 不能搭配管道使用。(我使用 more 是可以搭配管道使用的,不知道原作者为什么要这样写,麻烦校对确认一下这一句是否需要去掉)
`q` 即可退出 `more`
**更多示例**
打开 ostechnix.txt 文件进行交互式阅读,可以执行以下命令:
```
$ more ostechnix.txt
```
在阅读过程中,如果需要查找某个字符串,只需要像下面这样在斜杠(/)之后输入需要查找的内容:
```
/linux
```
`n` 键可以跳转到下一个匹配的字符串。
如果需要在文件的第 10 行开始阅读,只需要执行:
```
$ more +10 file
```
就可以从文件的第 10 行开始显示文件的内容了。
如果你需要让 `more` 提示你按空格键来翻页,可以加上 `-d` 参数:
```
$ more -d ostechnix.txt
```
![][2]
如上图所示,`more` 会提示你可以按空格键翻页。
如果需要查看所有选项以及对应的按键,可以按 `h` 键。
要查看 `more` 的更多详细信息,可以参考手册:
```
$ man more
```
### less 命令
`less` 命令也是用于打开指定的文件并进行交互式阅读,它也支持翻页和搜索。如果文件的内容太长,也会对输出进行分页,因此也可以翻页阅读。比 `more` 命令更好的一点是,`less` 支持向上翻页和向下翻页,也就是可以在整个文件中任意阅读。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/less-command-demo.gif)
在使用功能方面,`less` 比 `more` 命令具有更多优点,以下列出其中几个:
* 支持向上翻页和向下翻页
* 支持向上搜索和向下搜索
* 可以跳转到文件的末尾并立即从文件的开头开始阅读
* 在编辑器中打开指定的文件
**更多示例**
打开文件:
```
$ less ostechnix.txt
```
按空格键或回车键可以向下翻页,按 `b` 键可以向上翻页。
如果需要向下搜索,在斜杠(/)之后输入需要搜索的内容:
```
/linux
```
`n` 键可以跳转到下一个匹配的字符串,如果需要跳转到上一个匹配的字符串,可以按 `N` 键。
如果需要向上搜索,在问号(?)之后输入需要搜索的内容:
```
?linux
```
同样是按 `n` 键或 `N` 键跳转到下一个或上一个匹配的字符串。
只需要按 `v` 键,就会将正在阅读的文件在默认编辑器中打开,然后就可以对文件进行各种编辑操作了。
`h` 键可以查看 `less` 工具的选项和对应的按键。
`q` 键可以退出阅读。
要查看 `less` 的更多详细信息,可以参考手册:
```
$ man less
```
### most 命令
`most` 同样是一个终端阅读工具,而且比 `more``less` 的功能更为丰富。`most` 支持同时打开多个文件、编辑当前打开的文件、迅速跳转到文件中的某一行、分屏阅读、同时锁定或滚动多个屏幕等等功能。在默认情况下,对于较长的行,`most` 不会将其截断成多行显示,而是提供了左右滚动功能在同一行内显示。
**更多示例**
打开文件:
```
$ most ostechnix1.txt
```
![](https://www.ostechnix.com/wp-content/uploads/2018/11/most-command.png)
`e` 键可以编辑当前文件。
如果需要向下搜索,在斜杠(/)或 S 或 f 之后输入需要搜索的内容,按 `n` 键就可以跳转到下一个匹配的字符串。
![][3]
如果需要向上搜索,在问号(?)之后输入需要搜索的内容,也是通过按 `n` 键跳转到下一个匹配的字符串。
同时打开多个文件:
```
$ most ostechnix1.txt ostechnix2.txt ostechnix3.txt
```
在打开了多个文件的状态下,可以输入 `:n` 切换到其它文件,使用`↑` 或 `↓` 键选择需要切换到的文件,按回车键就可以查看对应的文件。
![](https://www.ostechnix.com/wp-content/uploads/2018/11/most-2.gif)
要打开文件并跳转到某个字符串首次出现的位置(例如 linux可以执行以下命令
```
$ most file +/linux
```
`h` 键可以查看帮助。
**按键操作列表**
移动:
* **空格键或 `D` 键** 向下滚动一屏
* **DELETE 键或 `U` 键** 向上滚动一屏
* **`↓` 键** 向下移动一行
* **`↑` 键** 向上移动一行
* **`T` 键** 移动到文件开头
* **`B` 键** 移动到文件末尾
* **`>` 键或 TAB 键** 向右滚动屏幕
* **`<` 键** 向左滚动屏幕
* **`→` 键** 向右移动一列
* **`←` 键** 向左移动一列
* **`J` 键或 `G` 键** 移动到某一行,例如 `10j` 可以移动到第 10 行
* **`%` 键** 移动到文件长度某个百分比的位置
窗口命令:
* **`Ctrl-X 2`、`Ctrl-W 2`** 分屏
* **`Ctrl-X 1`、`Ctrl-W 1`** 只显示一个窗口
* **`O` 键、`Ctrl-X O`** 切换到另一个窗口
* **`Ctrl-X 0`** 删除窗口
文件内搜索:
* **`S` 键或 `f` 键或 `/` 键** 向下搜索
* **`?` 键** 向上搜索
* **`n` 键** 跳转到下一个匹配的字符串
退出:
* **`q` 键** 退出 `most` ,且所有打开的文件都会被关闭
* **`:N`、`:n`** 退出当前文件并查看下一个文件(使用`↑` 键、`↓` 键选择下一个文件)
要查看 `most` 的更多详细信息,可以参考手册:
```
$ man most
```
### 总结
**`more`** 传统且基础的文件阅读工具,仅支持向下翻页和有限次数的向上翻页。
**`less`** `more` 功能丰富,支持向下翻页和向上翻页,也支持文本搜索。在打开大文件的时候,比 `vi` 这类文本编辑器启动得更快。
**`most`** 在上述两个工具功能的基础上,还加入了同时打开多个文件、同时锁定或滚动多个屏幕、分屏等等大量功能。
以上就是我的介绍,希望能让你通过我的文章对这三个工具有一定的认识。如果想了解这篇文章以外的关于这几个工具的详细功能,请参阅它们的 `man` 手册。
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/the-difference-between-more-less-and-most-commands/
作者:[SK][a]
选题:[lujun9972][b]
译者:[HankChow](https://github.com/HankChow)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
[2]: http://www.ostechnix.com/wp-content/uploads/2018/11/more-1.png
[3]: http://www.ostechnix.com/wp-content/uploads/2018/11/most-1-1.gif