如何將終端內容寫入文件


13

這是我的情況:我打開終端並運行程序,該程序在終端(文本)中顯示實時更新,每秒變化一次。該程序正在運行(退出該程序)時,只能使用" Enter"鍵。因此,您無法在控制台中輸入其他任何內容。

我想將終端內容寫入文件,就像每秒之後一樣。

我該怎麼做?通過打開第二個控制台並使用一些命令?無法通過setterm -dump命令使用它。

12

When you are executing your command from terminal instead of seeing the output on your console you can redirect it straight to a file. While the program runs your the output is going to be written to the file. An example lets say you want to write the contents of your folder with an ls command to a file called list.txt

ls > list.txt

The > operator redirects your output according to your needs.


16

You can pipe your output to the tee program (description):

my_program ... | tee my_program.log

This will show the ouput on the terminal, but also write it to the file my_program.log


2

Try using the script command. Unfortunately, it puts a lot of control character gobbledegook in the transcript. However, if you see this link at the NCSSM CS Site you will find an imperfect but pretty good solution to the problem.