1. Overview

In this quick tutorial, we’ll explore how the Linux script command can help us to create a typescript and thereby record all the terminal activity.

2. Syntax

Let’s start by having a look at the basic syntax:

script [OPTIONS] FILENAME

The script command is used to record the activity performed by a user, such as the commands a user types as well as the output of those commands.

In case we don’t specify a FILENAME, it automatically takes “typescript” as the default filename. Furthermore, we just need to type in the script command to start recording the session and exit at the end of the recording.

3. Recording the Current Terminal Activity

To illustrate the script command, let’s try running it without any parameters:

$ script firstRecording
Script started, file is firstRecording

$ date
Wed Aug  5 12:06:50 JST 2020

$ exit
exit
Script done, file is firstRecording

First, the script command creates a file with the name firstRecording. Then, this file will store all the commands that we type on the screen.

Next, we typed the date command on the terminal. In the background, the command and its output are recorded in the typescript file.

Lastly, we typed exit command on the terminal to exit from the recording session.

4. Viewing the Recorded Content

We can view the contents of the recorded file by opening the file, created by script command. In this case, we will use the cat command followed by the filename to open the file. We can see that script also contains the start and end times of our recording:

$ cat firstRecording
Script started on Wed 05 Aug 2020 12:06:47 PM JST

$ date
Wed Aug  5 12:06:50 JST 2020

$ exit
exit

Script done on Wed 05 Aug 2020 12:06:53 PM JST

5. Replaying the Recorded File

Additionally, the script command also allows us to record the contents of the session using the -timing flag:

$ script --timing=file_time firstrecording
Script started, file is firstrecording

$ date
Mon Aug 10 01:10:38 JST 2020

$ cal
     August 2020
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

$ exit
exit
Script done, file is firstrecording

As we can see below, we can view the created file using the cat command. Also, keep in mind that there will be another file created called file_time. This file contains the timing information for replaying the commands.

$ cat firstrecording
Script started on Mon 10 Aug 2020 01:10:27 AM JST
$ date
Mon Aug 10 01:10:38 JST 2020
$ cal
August 2020
Su Mo Tu We Th Fr Sa
1
2  3  4  5  6  7  8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
$ exit
exit

Script done on Mon 10 Aug 2020 01:10:56 AM JST

Finally, we can replay (view) the user activity on our console using the screenreplay command:

$ scriptreplay file_time firstrecording

6. Conclusion

In this quick tutorial, we’ve seen how to use the script command to record the terminal sessions.

We first covered how to record the current terminal activity and view the recorded file content.

Finally, we explored how to replay the recorded file.

guest
0 Comments
Inline Feedbacks
View all comments