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:
我通常使用 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.
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
发布评论
评论(7)
来自手册:
您还可以通过输入
-N
来切换行号而无需退出 less。可以通过这种方式切换 less 的任何命令行选项。
From the manual:
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.
您还可以在
less
打开时按=
来仅显示(在屏幕底部)有关当前屏幕的信息,包括行号,格式为:例如,屏幕当前显示
20530-20585
行,文件总共有1816468
行。You can also press
=
whileless
is open to just display (at the bottom of the screen) information about the current screen, including line numbers, with format:So here for example, the screen was currently showing lines
20530-20585
, and the files has a total of1816468
lines.您可以在管道传输到
less
之前通过cat -n
过滤文件:或者,如果您的
less
版本支持它,则- N 选项:
You could filter the file through
cat -n
before piping toless
:Or, if your version of
less
supports it, the-N
option:命令行标志
-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 ofless
's command line options in this way.您可以设置环境变量以始终将这些选项应用于所有 lessd 文件:
You can set an enviroment variable to always have these options apply to all less'd file:
如果您点击 = 并期望看到行号,但只看到字节计数,则行号将被关闭。 按 -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 insideless
as needed.上面的答案显示了如何在启用行号的情况下启动 less,
但对于那些想知道如何在已使用 less 查看的文件中打开和关闭行编号的人
: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
Courtesy: lostsaloon