使用“less”命令时,如何将终端上显示的内容重定向到文件?

αғs*_*нιη 19 command-line redirect less

我如何将终端内容(当前我在使用less命令时查看的不是整个文件的内容)重定向到输出文件,直到我按Q退出less

Syl*_*eau 29

要仅保存当前显示在终端中的部分,您可以使用该|命令。

来自man less

| <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.
  If <m> is '.' or newline, the current screen is piped.
Run Code Online (Sandbox Code Playgroud)
  1. 所以第一种类型|(管道符号)
  2. 然后选择.标记以仅选择终端上可见的内容(或直接点击Enter
  3. 使用tee保存到一个文件,例如:tee /tmp/section_of_big_file.txt
  4. Enter然后按q

带截图的序列:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明