如何将less中的所有行写入文件?

Fli*_*imm 96 less

我已将命令通过管道传输到less,现在我想将命令的输出保存到文件中。我怎么做?

在这种情况下,我不想使用tee,我想直接从less中找到解决方案,这样如果我忘记使用tee.

这个问题类似于这个,唯一的区别是我想保存所有的行,而不是一个子集:Write lines to a file from less

don*_*sti 139

从less,键入s然后键入要保存到的文件名,然后Enter。
从man页面,在COMMANDS:

s filename
      Save the input to a file.  This only works if the input is a pipe, not an ordinary file.
Run Code Online (Sandbox Code Playgroud)

man页面还指出,根据您的特定安装,该s命令可能不可用。在这种情况下,您可以转到第 1 行:

g or < or ESC-<
      Go to line N in the file, default 1 (beginning of file).
Run Code Online (Sandbox Code Playgroud)

并将整个内容通过管道传输到cat:

| <m> shell-command
      <m> represents any mark letter. Pipes a section of the input file to the
      given shell command. The section of the file to be piped is between the
      first line on the current screen and the position marked by the letter. 
      <m> may also be ^ or $ to indicate beginning or end of file respectively.
Run Code Online (Sandbox Code Playgroud)

所以要么:

g|$cat > filename
Run Code Online (Sandbox Code Playgroud)

或者:

<|$cat > filename
Run Code Online (Sandbox Code Playgroud)

即输入g或<(g或小于)| $(管道然后美元)然后cat > filename和Enter。
无论输入是管道还是普通文件,这都应该有效。