Previous Table of Contents Next

Module 116


The external script command makes a copy (typescript) of a terminal session. When you run script a new shell is forked. This new shell makes a complete copy of everything displayed on your terminal. It reads standard input and output for your terminal tty and stores the data in a file. The default filename is typescript.

To exit from a script session you simply press Ctrl-D or type exit.


Following is the general format of the script command.

     script [ -a ] [ file ]


The following option may be used to control how script functions.

-a Append the output of script to file. Normally script begins writing to a new file; if the file exists it is overwritten unless you specify the -a option.


The following argument may be passed to the script command.

file The file script uses to save all data.
If no file is specified then the file named typescript is used.


Refer to the tee command described in Module 134.


If no output file is specified, the output of script is placed in the typescript file.


The most common use of script is to make a copy of a terminal session. By starting script you can save all the information, displayed on your terminal during a login session, to a file. You can then print the file or view it with an editor.

Remember, if you used applications with cursor control, those control characters will reside in the output file produced by script. Therefore, if you send the file to a printer or terminal, it may not print or display properly. You can use the col command to remove control characters from the typescript file.


In this activity you use the script command to make a typescript of a few commands. Begin at the shell prompt.

1.  Type script and press Return. Your output is saved in the typescript file.
     cj> script
     Script started, file is typescript
2.  Now perform several UNIX commands. For example, type ls and press Return.
3.  Type cat /etc/group and press Return to have output sent from the computer to your terminal.
4.  Now stop script from tracing. Type exit and press Return.
     cj> exit
     Script done, file is typescript
5.  Display the output of script by typing more typescript and pressing Return.
6.  Type rm typescript and press Return to remove the output file created by script.
7.  Turn to Module 60 to continue the learning sequence.

Previous Table of Contents Next