我如何将终端内容(使用命令时,我当前正在查看的内容而不是整个文件less
)重定向到输出文件中,直到我按下Q退出less
?
答案1
要仅保存终端中当前显示的部分,您可以使用该|
命令。
从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
带截图的顺序: