How to Record Terminal Session in Ubuntu

Spread the love

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

sudo apt-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 -a 2> /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 -a 2> /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.

Is this helpful to you? What other uses can you think of?

Image credit: Macro Of Digital Dictaphone by BigStockPhoto

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Damien Oh

Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.

Comments (2)