Record your Terminal activity using ‘Script’ Command

As a System administrator, you will run a lot of commands in the Terminal everyday. Sometimes you might want to refer the entire command history along with all respective outputs later. And, If you’re a programmer and write a program that displays a really long output in Terminal, you can’t scroll up to certain limit and can’t view the entire output of your Terminal session. If you’re a technical writer, you must include what command you used in the Terminal and it’s output in your guides. So, I believe It is always a best idea to record the Terminal session, and keep it aside for future reference. There are many tools out there to record your Desktop. Unfortunately, there are no such tools for servers that only has CLI session. Luckily, we have a simple command called script that allows us to make typescript of everything printed on the Terminal.

Script command allows you to record everything you do in your Terminal, and saves the output in a text file. This command comes pre-installed with most Linux, and Unix-like operating systems. In this brief tutorial, let me show you how to use script command to record your Terminal session.

Script command usage

When you’re ready to recording the Terminal activity, just type:

$ script

You will get a message something like below.

Script started, file is typescript

Now, everything you entered in the Terminal will be saved in a file called typescript.

Also, you can give a custom name to the typescript by specifying a file name of your choice as shown below.

$ script -a my_terminal_session

Now, Let us type few commands, and see how it works.

$ whoami

$ uname -a

$ cd /home/sk/Soft_Backup

$ ls -l

$ mkdir ostechnix

$ rmdir ostechnix

That’s enough for now. You can try as many commands as you want to record. Once you are done, type ‘exit’ in the Terminal to stop recording.

$ exit

Sample output:

exit
Script done, file is typescript

As you see in the above screenshot, the script command’s output will be stored in file called “typescript” in the current working directory.

Voila! As you see in the above output, Script command recorded and displayed everything I have entered in the Terminal. For the sack of easy reference, I have marked the commands that I executed in bold letters.

You could use the output for your assignment, or just save this output for future reference.

For further details, I recommend you to refer the man pages.

$ man script

That’s all for now folks. If you want a hardcopy record of the Terminal session for future reference, or for an assignment, script command is good tool to try.

If you find this tutorial, please share it on your social, professional networks and support OSTechNix.

2 Responses

I rewrote script in Python: http://stromberg.dnsalias.org/~strombrg/pypty/ . Its chief benefit is that it has a “dated files” mode, so if you leave a session running overnight, a new file will be started for the new day. This makes it easier to look things up later. The distribution also includes script-replay, which makes it easy to move forward and back through a typescript; it has a curses interface (arrow keys) and a GTK (buttons) interface.

Hello Dan, I visited the link you have mentioned. Your script seems good and might be useful for users. If you have time, please write a review or how-to guide about your script with few examples and send it to me by using the contact form. If it is good, I will publish on our blog, and let us promote your script. Thank you for letting me about your script. https://www.ostechnix.com/contact-us/