Linux script command - A recorder inside your Terminal

May 30, 2014 | By
| 2 Replies More

When you are working on the terminal or console, you may want to record what you have done in the terminal. The recording can be used as a documentation about what happen in terminal. Let say you are working together with some Linux Administrators at the same time. Or you let someone to remote your server. You may want to record about what happen in the terminal. To do this, you can use script command.

What is script

script is a command that make a typescript that printed in the terminal. It is useful for everyone who need a hardcopy record of the session that happened in the terminal. This record can be saved and printed out later.

How to use it

By default, we can start script with typing script on the terminal.

pungki@dev-machine:~$ script
Script started, file is typescript

You can also define a destination filename to write the result of typescript.

pungki@dev-machine:~$ script myfile

Define script file

When you received a command prompt again, it means the terminal will record anything that is printed in terminal.

You will see in the current directory, there is a file named typescript.

Why we use script command

As we mention before, script has main function to record everything. Here’s two samples of scenarios why we are using it.

Collaborate with colleague

When working together with your colleague, we can record your activity with script.
Let say we will use a typescript file called collaborate. To do that type :

$ script collaborate

Create collaborate file

Then after doing some tasks, let say you need to send your work to another engineer. Just send the file. So when the other engineer need to review what was done, he can just open the file using a text editor.

If he want to update the file, he can use -a option.

$ script -a collaborate

Append the file

Record someone activity in the terminal

You may let your engineer or someone to enter your system remotely. To make sure that your engineer are doing right, you can record what he had done to your system. To make the script command run automatically upon login, we can add it on your shell profile. If you are using bash shell, add this line into your bash profile.

$ vi ~/.profile

# run the script command to record everything
# use -q for quite and -a option to append the script
/usr/bin/script -qa /usr/local/script/log_record_script

Add script to bash profile

Then save it. Next time he logged in to your system, script command will automatically run and put the log on the /usr/local/script/log_record_script

Script without notification

The option -q will run script command in quite mode. The user who logged in will not have any notification that the script command is run. While -a option will add the record without erasing the previous record.

If we don't use -q option, then when the user logged on, the user will get a notification about script as the picture below.

Script with notification

Quit recording

To exit the record activity, we can press Ctrl+D button or type exit from the terminal. Before you exit from script, you will find the size of the record file is 0 Kb. After you exit from script, the file size will change.


Script command may useful when you need to record or documenting what happen in the terminal. The record file will be stored as a text file, so it will easy to open it with any text editor. As usual, we can always type man script or script -h to display its manual page and explore it more detail.


Free Linux Ebook to Download

Comments (2)

Trackback URL | Comments RSS Feed

  1. Jeanmichel Cote says:

    I have written a couple of useful functions in a ~/.functions file which is sourced on login. The functions work fine when used in regular shell but when i do "script record.text" and then try to run the same functions, weirdly, "bash: myfunc: command not found".

    As soon as i exit the "script" state, my functions are available as usual.

    Any idea why is that?

  2. IC says:

    Is it possible to time a script cmd?
    Something like:
    Script text.log && exit | at now +5 minutes
    or any other idea :) ?

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.