bsdutils package is the tool you want.
# bunch of commands
and all the commands you typed, and all their output (including cursor control, which depends of the setting of
$TERM) will be saved in
bionic (1) script.1.gz
Provided by: bsdutils_2.31.1-0.4ubuntu3_amd64 bug
script - make typescript of terminal session
script [options] [file]
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.