1

Is there any way to always save the content of whatever is happening on terminal window to a file?

I want to save each and every command that is being executed and its output to a file to keep track of change history and I want to enable it up permanently on terminal.

Any suggestions pls?

  • This used to work as mentioned here: https://askubuntu.com/questions/161935/how-do-i-log-all-input-and-output-in-a-terminal-session, however, script does not seem to work anymore. You may want to refer to that question and indicate it does not work anymore to avoid it from being marked as a duplicate – vanadium Jan 04 '20 at 09:18

2 Answers2

1

script,from the bsdutils package is the tool you want.

script my.log 
# bunch of commands
exit

and all the commands you typed, and all their output (including cursor control, which depends of the setting of $TERM) will be saved in my.log.

From the man page:

bionic (1) script.1.gz
Provided by: bsdutils_2.31.1-0.4ubuntu3_amd64 bug

NAME

       script - make typescript of terminal session

SYNOPSIS

       script [options] [file]

DESCRIPTION

       script  makes  a  typescript  of  everything displayed on your terminal.  It is useful for
       students who need a hardcopy record of an interactive session as proof of  an  assignment,
       as the typescript file can be printed out later with lpr(1).

       If  the argument file is given, script saves the dialogue in this file.  If no filename is
       given, the dialogue is saved in the file typescript.
waltinator
  • 36,399
0

You can use this for appending to a file without overwriting.

your_command >>/path/to/file

You can also check .bash_history for the order of commands.

This answer might help.

Sharan
  • 121
  • Question is to save anything that is also printed to the screen into a file. Your answer 1) requires to add the redirection to each command and 2) will not print the command itself – vanadium Jan 04 '20 at 09:23