如何以“less”显示行号 (GNU)

发布于 2024-07-18 06:29:16 字数 93 浏览 10 评论 0原文

使 less 在左栏中显示行号的命令是什么?

What is the command to make less display line numbers in the left column?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

我不咬妳我踢妳 2024-07-25 06:29:16

来自手册

-N 或 --行号
导致在每个行的开头显示行号
显示屏中出现一行。

您还可以通过输入 -N 来切换行号而无需退出 less。

可以通过这种方式切换 less 的任何命令行选项。

From the manual:

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

You can also toggle line numbers without quitting less by typing -N.

It is possible to toggle any of less's command line options in this way.

最单纯的乌龟 2024-07-25 06:29:16

您还可以在 less 打开时按 = 来仅显示(在屏幕底部)有关当前屏幕的信息,包括行号,格式为

myfile.txt lines 20530-20585/1816468 byte 1098945/116097872 1%  (press RETURN)

:例如,屏幕当前显示 20530-20585 行,文件总共有 1816468 行。

You can also press = while less is open to just display (at the bottom of the screen) information about the current screen, including line numbers, with format:

myfile.txt lines 20530-20585/1816468 byte 1098945/116097872 1%  (press RETURN)

So here for example, the screen was currently showing lines 20530-20585, and the files has a total of 1816468 lines.

合久必婚 2024-07-25 06:29:16

您可以在管道传输到 less 之前通过 cat -n 过滤文件:

cat -n file.txt | less

或者,如果您的 less 版本支持它,则 - N 选项:

less -N file.txt

You could filter the file through cat -n before piping to less:

cat -n file.txt | less

Or, if your version of less supports it, the -N option:

less -N file.txt
梦途 2024-07-25 06:29:16

命令行标志 -N--LINE-NUMBERS 导致在显示屏中每行的开头显示行号。

您还可以通过输入 -N 来切换行号,而无需退出 less。 可以通过这种方式切换 less 的任何命令行选项。

The command line flags -N or --LINE-NUMBERS causes a line number to be displayed at the beginning of each line in the display.

You can also toggle line numbers without quitting less by typing -N<return>. It it possible to toggle any of less's command line options in this way.

尛丟丟 2024-07-25 06:29:16

您可以设置环境变量以始终将这些选项应用于所有 lessd 文件:

export LESS='-RS#3NM~g'

You can set an enviroment variable to always have these options apply to all less'd file:

export LESS='-RS#3NM~g'
玉环 2024-07-25 06:29:16

如果您点击 = 并期望看到行号,但只看到字节计数,则行号将被关闭。 按 -n 将其打开,并确保 $LESS 不包含“n”。

默认情况下关闭行号(例如,设置 LESS=n)可以加快在非常大的文件中的搜索速度。 如果您经常搜索大文件,但通常不关心您在哪一行,那么它会很方便。

我通常使用 LESS=RSXin 运行(启用转义码,截断长行,退出时不清除屏幕,忽略所有小写搜索的大小写,默认情况下不计算行号)根据需要从 less 内部使用 -n-S

If you hit = and expect to see line numbers, but only see byte counts, then line numbers are turned off. Hit -n to turn them on, and make sure $LESS doesn't include 'n'.

Turning off line numbers by default (for example, setting LESS=n) speeds up searches in very large files. It is handy if you frequently search through big files, but don't usually care which line you're on.

I typically run with LESS=RSXin (escape codes enabled, long lines chopped, don't clear the screen on exit, ignore case on all lower case searches, and no line number counting by default) and only use -n or -S from inside less as needed.

不离久伴 2024-07-25 06:29:16

上面的答案显示了如何在启用行号的情况下启动 less,
但对于那些想知道如何在已使用 less 查看的文件中打开和关闭行编号的人

查看器内部
当您查看文件内容时,您还可以从 less 查看器内部切换行号。 这很有用
如果您已经在查看器内或者想要删除该线
号码显示。 与 less 的大多数命令行选项一样,您可以
也可以在查看器中使用它...

当显示文件内容时,只需使用 -N 即可
键盘,然后按 Enter 键以显示行号。 你可以隐藏
再次输入 -N(或 -n),然后按 Enter from 来输入行号
与查看器中。 这是切换行号和
比命令行选项方便得多

lostsaloon

the above answers shows how to initiate a less with line numbers enabled,
but for those who want to know how to toggle line numbering ON and OFF in the file already being viewed with less

Inside the Viewer
You can also toggle the line numbers from inside the less viewer, as you are viewing the file content. This is useful
if you are already inside the viewer or if you want to remove the line
number display. As with most command line options of less, you can
also use it from with in the viewer…

When the file content is being displayed, just type -N using the
keyboard and followed by Enter to display line numbers. You can hide
the line numbers by typing -N (or -n) again followed by Enter from
with in the viewer. This is a quick way to toggle line numbers and
much more convenient than the command line option

Courtesy: lostsaloon

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文