首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >较少的-n默认行为,与通过man指示的行为不同。

较少的-n默认行为,与通过man指示的行为不同。
EN

Unix & Linux用户
提问于 2022-01-21 13:03:28
回答 1查看 37关注 0票数 0

对于MacOS和Ubuntu 20,使用man less命令,我可以读取以下内容:

代码语言:javascript
复制
 -n or --line-numbers
              Suppresses line numbers.  The default (to use line numbers) may cause less to run more slowly in some cases, especially with a very large input file.  Suppressing line  numbers  with
              the  -n  option will avoid this problem.  Using line numbers means: the line number will be displayed in the verbose prompt and in the = command, and the v command will pass the cur‐
              rent line number to the editor (see also the discussion of LESSEDIT in PROMPTS below).

 -N or --LINE-NUMBERS
              Causes a line number to be displayed at the beginning of each line in the display.

这篇文章的原因是关于包含-n部件的The default (to use line numbers) (小写)参数。对于提到的这两个操作系统,如果我这样做的话:

  • less /path/to/filename.txt

它显示没有行号的数据,正相反,如上文所示。

当然,如果我想看到我使用的行号:

  • less -N /path/to/filename.txt

它按指示工作。因此:

代码语言:javascript
复制
less    /path/to/filename.txt
less -n /path/to/filename.txt

几乎都一样。

我是不是遗漏了什么?

顺便说一下,用less --help

代码语言:javascript
复制
-n  -N  ....  --line-numbers  --LINE-NUMBERS
                  Don't use line numbers.

不是很清楚,是混淆了。

我创建这个帖子的原因是以下有价值的帖子:

在解决方案中指出:

代码语言:javascript
复制
You can, however, run "less -n +F", which causes "less" to read 
only the end of the file, at the cost of **not** displaying line numbers
EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2022-01-21 13:05:32

less以两种方式显示行号:

  • 在每一行的开头,如果使用-N
  • 在屏幕底部的status行中,启用详细提示时(less -M;这将显示显示的第一行数、最后一行和总行数)。

-n禁用了后者,以及前者。特别是,确定行的总数可能很昂贵;这就是为什么这个选项是有用的。使用-n禁用行号时,less以字节显示文件中的位置。

我的less版本在less --help中有以下内容:

代码语言:javascript
复制
  -n  ........  --line-numbers
                  Don't use line numbers.
  -N  ........  --LINE-NUMBERS
                  Use line numbers.

您显示的信息描述了-n的行为:

使用行号意味着:行号将显示在详细提示符和=命令中,v命令将当前行号传递给编辑器

这没有提到每行开头的行号。

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/687315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档