How to Record terminal sessions in ubuntu

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

While working on ubuntu we have to use terminal at a great extent. When we have to deal with the system configuration in ubuntu we generally took the help of Ubuntu terminal. Ubuntu terminal is very useful while interacting with ubuntu system. sometimes we have to save our terminal sessions, so that we could see and understand all the activities during the process for future reference. In linux ‘script’ is the command to perform this action. With the help of script we can save our terminal logs in a file. So We can have a glance on our work after finishing it. ‘Scriptreplay’ is another command which would perform a full automatic replay of the terminal session. Here I will help you to learn , how to record the terminal session in ubuntu.

Also we can use the ‘History’ command for this purpose but it doesn’t save the output. While using the script command we can view the output of a command in history from the Log file.

Recording Linux terminal using script command

We can use the script command to store the terminal activities in a log file. We can name the log file , otherwise it would take the default file name ‘typescript’.

So now let’s have a look on how script command works. now you can see that here I am using the name myscript for my log file.

# Script myscript.log

Now immediately after that I inserted few of the commands such as cal, w, whoami. So now all of these commands are stored in the file with their outputs as shown below.

record terminal session

So next we have to check the log file for the saved output with their respective commands. To check that enter the following command.

# vi myscript.log
record terminal session

As now, here we can see that all the commands with their respective outputs . Next we can also use the -a option to append the output to the log file as shown below.

# script -a myscript.log

Then if we want to save the output of a single command without an interactive session, we can use -c as shown below.

# script -c 'hostname' script.log
record terminal session

Surprisingly , you would be happy to know that we can also store the timing information using the –timing option as shown below.

# script -timing=time.txt myscript.log

Now you can also check the timing file as shown below with the following command.

# vi time.txt

Conclusion

In this tutorial I made an effort to help you to be familiar with script commands. So that will further help you to record terminal session and have a glance on it anytime later. I hope you’ve liked the tutorial. You can also take a look on my other installation article such as Zabbix server , Bodhi linux etc.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook