Jan 292011

tuxThe script command is part of the util-linux-ng package and so should be available already installed in any distribution, or you should be able to easily add it.

What’s script ?

From his man page:

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the type script file can be printed out later with lpr.

Basic usage from a terminal type script this will start a new session and write all the command in the file typescript (in your home).

But now we’ll see how to use it to record a whole session and than replay it:


script -t -a /tmp/mylog.out 2&> /tmp/mylog.time;


-a Append the output to file or typescript, retaining the prior contents.

-t Output timing data to standard error. This data contains two fields, separated by a space. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. This information can be used to replay typescripts with realistic typing and output delays.

After this command do your work session and end it with ^D (Ctrl-D) or”exit”

Now you’ll find in /tmp the 2 files mylog.out and mylog.time.


 scriptreplay /tmp/mylog.time /tmp/mylog.out

Sciptreplay it’s script companion, take as input the output produced with script and do a replay of them.

The replay simply displays the information again; the programs that were run when the typescript was being recorded are not run again. Since the same information is simply being displayed, scriptreplay is only guaranteed to work properly if run on the same type of terminal the typescript was recorded on. Otherwise, any escape characters in the typescript may be interpreted differently by the terminal to which scriptreplay is sending its output.

All together:

% script -t 2&> demo.timing -a demo.session
Script started, file is demo.session
% exit
Script done, file is demo.session
% scriptreplay demo.timing demo.session

Example of scriptreplay:

Popular Posts:

Flattr this!

  8 Responses to “Record your terminal with Script”

  1. Hello

    I am on Kubuntu 9.04. I have script installed but
    util-linux-ng seems not to exist.

    When I use your command
    script -t -a /tmp/mylog.out 2&gt ; /tmp/mylog.time ;
    I obtain an error

    gt: Command not found.

    • Thanks for the feedback, wrong encoding after publishing the article 🙁

      The correct command is:
      script -t -a /tmp/mylog.out 2&> /tmp/mylog.time

      Fixed also in the article.

  2. If you start the script command in the home directory, then yes, typescript will be written to the home directory, otherwise it will be written to the directory where you start the script command.

    You can always specify the filename, and location that the output will be written:

    script ~/capture.txt

    This will write the output to capture.txt in your home directory.

  3. script -t -a /tmp/mylog.out 2&> /tmp/mylog.time

    gives for me:
    Invalid null command.

  4. May be
    script -t 2> demo.timing -a demo.session

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>