Linux script command with examples

In this article, we are going to see Linux script command with examples.

Linux script command is used to make typescript or record all the terminal activities. After executing the script command it starts recording everything printed on the screen including the inputs and outputs until we type exit on terminal.

When you run the script command without a log file name, it attempts to write to the default file typescript in the current working directory.

Linux script command syntax:

script [options] - -timing=timing_file log_filename

Where it is useful:
1. When we want to record activities of terminal for auditing purposes.
2. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment.

Linux script command examples:

1. To start recording of terminal, type script then add the filename to record all the activities to store on the terminal.

script logdata_$(date +%d%m%Y%H%m).log

Linux script command with examples

Once we enter the a above command, you receive message ‘script started‘ and filename. Recording continues until we type exit.

2. Now type the exit command on the terminal.

exit

3. We can use -a option to append to the existing log file.

script -a logdata_$(date +%d%m%Y%H%m).log

4. To log results of a single command other than an interactive shell session, use the -c option. After first command execution script command stops.

script -c logdatac_$(date +%d%m%Y%H%m).log

From the above output, date is the command appended to existing log file.