A QUICK REFERENCE TO SCRIPT
You can capture the output of a command by redirecting it to a file. What do you do if you want to save the output of several commands, or the commands you run are interactive, so you need to see what they ask to give the correct responses?
The solution is a program called script. Run this from a terminal, with no arguments, and nothing will appear to happen apart from a message that script has started. Now run some other commands and everything appears to be just the same as normal. In fact, script has opened a subshell and is both displaying and capturing everything from whatever you type. Not only the output from the commands but your input too, even the shell prompts. Some programs behave differently when their output is not a TTY (a shell), for example if you redirect a command’s output to a file, it no longer colourises the output. Because script is running a shell, the output is exactly as you see in the shell.
When you’ve finished, press Ctrl+d to exit the subshell and you are back in your original shell, with a file called typescript that contains a transcript of your script session. If you specify a file name after the command, script will use that instead. You can specify a command name with -c. Script will then run that command and exit.
There are other options you can use, such as --timing, which outputs timing information to a separate file. This is useful with scriptreplay, which outputs the typescript information, optionally with the same timing, without running the commands again. This comes in handy when giving a presentation, as you can run and record any commands you want to show, then replay them without having to hope they still work!