問題描述
在我按 Q
從 less
退出之前,如何將終端內容(使用 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.
-
所以首先輸入
|
(管道符號) -
然後選擇
.
標記以僅選擇終端上可見的內容(或者隻需點擊Enter
) -
使用
tee
保存到文件,例如tee /tmp/section_of_big_file.txt
-
按
Enter
然後按q
帶截圖的順序: