Ubuntu – How to capture text from a specific terminal and redirect it to a log file while simultaneously working?


I viewed this question to redirect text to file while displaying the output. My question is how can I redirect it while working AND without constant | tee command.

My plan is to use this question to identify terminal (Gnome or Guake) and record only Gnome for my Linux commands testing. So I need constant and immediate redirecting of commands and their outputs (with errors) to a file (say cmdlog.log).

Best Answer

The script command can do this, it starts a session and all output is by default captured into a file called typescript. Alternatively, one can specify the filename to contain the captured session, e.g.

script capture.txt

..then run your commands and finally type "exit" to exit the session.

To ensure you don't get any control characters, use:

script capture.txt

and when you exit, use:

col -b < capture.txt > cleaned-capture.txt
Related Question