当前位置: 首页>>技术教程>>正文


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

, ,

问题描述

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

最佳方法

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

来自 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.
  1. 所以首先输入 |(管道符号)

  2. 然后选择 . 标记以仅选择终端上可见的内容(或者只需点击 Enter )

  3. 使用 tee 保存到文件,例如tee /tmp/section_of_big_file.txt

  4. Enter 然后按 q

带截图的顺序:

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13457.html,未经允许,请勿转载。