We have moved to www.dataGenX.net, Keep Learning with us.

Monday, December 24, 2012

The Unix "SCRIPT" command : a command recorder

script is a standard Unix command that records a script of your interaction with the Unix system. Once it's started, it works "in the background", meaning that you continue to work normally, but the script session is dumping everything that shows up on your screen (more or less*) into some file. It probably would be better called carbon-copy. 

The most common use of script  is to document terminal session. By running script you log all the information displayed on your terminal. You can then print the log file or view it with an editor. In a way script is a specialized tee for the shell.

To start a script session, issue the command script to the Unix shell; then continue on working normally as long as you like. If you don't provide a file name to the script command, it places its output in a default file named typescript, you can name your script file hwn.txt, where n is the number of the programming assignment you're doing. 

Whatever you do, do not use the name of your program's source code file as the filename for the output of the script command. If you type script hello.c, the output from the script command will overwrite and destroy whatever used to be in hello.c  

When you decide you don't need to record stuff anymore, exit from the scripting session by issuing the command exit to the Unix shell.

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.

Format of the script command.
     script [ -a ] [ typescript_file ]

-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. 
This is the only option present in all versions of Unix.

Exp :
 script log1.txt
script –a log1.txt

till then...
njoy the simplicity.......