How to Record Terminal Session in Ubuntu

If you are a frequent terminal user, you may come across situations where you need to debug the code or copy the output of a script for future reference. For such cases, you may want to record the terminal session to obtain the log file of all the input commands you have entered and their outputs. Here is one way that you can use to record terminal session in Ubuntu.

Setting Up

Open a terminal and install bsdutils

sudoapt-get install bsdutils

Once installed, you will be able to use two commands script and scriptreplay to record the existing session and play back the recording.

Usage

The usage is pretty simple. To start the recording, you just need to use the command:

script -t-a2>/path-to/timing-file.txt /path-to/recording-file.txt

Remember to change the file path to a valid file location. For example, if I want to save the recording to my Home folder, this is what I type:

script -t-a2>/home/damien/timing.txt /home/damien/recording.txt

The “-t” flag instructs the script to output the timing data while the “-a” flag instructs the script to append the output.

Once you entered the command, you should see the line “Script started...“. Everything that you enter in the Terminal (including its output) will now be recorded.

Once you are done with the recording, simply type exit to end the recording. You should see the line “Script done,...” that denotes the end of recording.

To view the recording, you can either open the saved file (recording.txt) in your text editor or use the command scriptreplay

scriptreplay ~/timing.txt ~/recording.txt

That’s it. While it is simple, it can be really useful for debugging, or even troubleshooting your friend’s computer by showing them what you have typed and the expected output they should see in the terminal.