Man*_*dan 5 command-line less options
根据本教程用于less导航目的
表示:
g Go to the first line in the file.
p Go to the beginning of the file.
Run Code Online (Sandbox Code Playgroud)
我测试了两者,当然结果是相同的(当然使用G到底部)并测试每一个。
但乍一看 ifg和G彼此相反,它们足以分别进入第一行(顶部)和最后一行(底部) - 那么为什么会有这个选项,p如果它与 相同g?
Mar*_*ler 11
他,这是错误地描述了这些命令的实际作用。p是“百分比”。
尝试输入20p,您将跳转到文件长度的 20%。漂亮!
20g也有效,但它转到第二十行。
只需键入g或p仅暗示0g或0p;因为第零行和第零字节都是文件的开头,所以结果是相同的。
你可以很容易地测试它;我假设你正在使用zsh:
#!/usr/bin/zsh
(for i in {1..1000}; echo $i) | less
Run Code Online (Sandbox Code Playgroud)
将显示 1000 行编号,并将33g跳转到第 33 行,但33.3p会跳转到第 333 行:)
小智 6
它在less帮助(less文件,按h)中说您可以使用 转到文件的百分号p。例如,您可以在提示50p中执行操作less,它将转到文件的 50% 点(中间点)。我认为它转到文件开头的原因是因为您没有在 之前提供数字(用于何处)p,所以它只是转到开头。
例如:
$ less example.txt
Run Code Online (Sandbox Code Playgroud)
示例.txt:
This is the start
This is the middle
This is the end
Run Code Online (Sandbox Code Playgroud)
当我做50p:
This is the middle
This is the end
~
~
~
~
~
~
Run Code Online (Sandbox Code Playgroud)
当我做p:
This is the start
This is the middle
This is the end
~
~
~
~
Run Code Online (Sandbox Code Playgroud)