當前位置: 首頁>>技術教程>>正文


使用 ‘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/zh-tw/article/13457.html,未經允許,請勿轉載。