![使用“less”命令时,如何将终端上显示的内容重定向到文件?](https://linux22.com/image/978942/%E4%BD%BF%E7%94%A8%E2%80%9Cless%E2%80%9D%E5%91%BD%E4%BB%A4%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%B0%86%E7%BB%88%E7%AB%AF%E4%B8%8A%E6%98%BE%E7%A4%BA%E7%9A%84%E5%86%85%E5%AE%B9%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%E6%96%87%E4%BB%B6%EF%BC%9F.png)
我如何将终端内容(使用命令时,我当前正在查看的内容而不是整个文件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
带截图的顺序: