Some times its require to record your terminal sessions for future use or some sort of educational purpose. Recording terminal session can be achieved by installing script command(Most ofthe distributions install this application by default). If the command is not there try to install the package which provides it.
Install script command in Linux(Redhat/Fedora/CentOS) Operating systems
Installing script command in Linux(Ubuntu/Debian) Operating systems
apt-get install bsdutils
Once you install the application you will get two commands one for recording the terminal session(The script command) and playing the recorded terminal session(The scriptreplay command).
Recording your terminal: To record your terminal you have to use script as shown below. Once this command is executed you start using your terminal as you use normally.
script -t -a 2> /tmp/time.txt /tmp/record.txt
-t for mentioning the time so that separate time stamps are logged in to /tmp/time.txt file and -a for appending those time stamps to /tmp/time.txt file. If you see in the above command we used error redirect(2>), this is nothing but File descriptor to send time details to /tmp/time.txt. and the last file /tmp/record.txt records your keystrokes and their outputs.
How it works?
When you run the above command, it will say the script started. From this point the script command monitors the time and keeps track of the time changes. Onc user typed some words, it use the time difference between each keystroke user typed and store that time changes in the time file. The keys what he pressed is stored in /tmp/record.txt file. For example I clipped a time file for your reference.
If you see its just have numbers nothing more than that.
How about recorded data file /tmp/record.txt content?
Script started on Thu 04 Apr 2013 11:18:21 AM IST [email protected]:~$ asdf asdfNo command ‘asdf’ found, did you mean: Command ‘asdfg’ from package ‘aoeui’ (universe) Command ‘sadf’ from package ‘sysstat’ (main) Command ‘sdf’ from package ‘sdf’ (universe) asdf: command not found [email protected]:~$ asdf No command ‘asdf’ found, did you mean: Command ‘asdfg’ from package ‘aoeui’ (universe) Command ‘sadf’ from package ‘sysstat’ (main) Command ‘sdf’ from package ‘sdf’ (universe) asdf: command not found [email protected]:~$ exit
Script done on Thu 04 Apr 2013 11:18:30 AM IST
Once you start script command, it will start recording your session by displaying below line
[email protected]:~$ script -t -a 2> /tmp/time.txt /tmp/record.txt Script started, file is /tmp/record.txt
Once you completed executing your command execution, you can exit the script command by type exit or pressing Ctrl+d
If you see it say’s that the script file done writing data to the file. From that file you can view what are the commands you executed and their output by using cat command. But this will not give a simulated output. If you want simulated output you can use scriptreplay command as shown below.
scriptreplay /tmp/time.txt /tmp/record.txt
scriptreplay command takes two files as input, one for time stamps and other for recorded data file. Still have queries? See our youtube video how to do it yourself below. Please subscribe to our channel byclicking here.
My name is Surendra Kumar Anne. I hail from Vijayawada which is capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. I work with ICE systems, Sydney as Sr. Consultant. You can contact me at surendra (@) linuxnix dot com.