How to Run “script” Command in Linux?

0 12

The script command is used to typescript or record all terminal processes. After running the script command, it begins recording everything that appears on the screen, including inputs and outputs, until it exits.

If you don’t specify any argument, the “typescript file” will be created in the directory to save the terminal record.

The script command records both standard input/output and time of execution.

This post describes what the “script” command is and how it works with various options.

Syntax:

Follow the below-given syntax of “script” command:

$ script [option] [filename]

Let’s discuss some examples.

Example 1:

Using Script Command Without Any Argument

To start, type “script” without specifying any parameters. If no parameter is specified, script will create a “typescript” file in the directory to save the record.

The “script” would begin recording that can be stopped anytime with the “exit” command. Various scripts can be run in the meantime.

Simply run the exit command to end typescript, and the script will end the capture process:

Example 2:

Using “script” Command with Argument

Specify any file name as an argument. For instance, I am creating a text file by the name of “linuxhint.txt”. Run the following command:

Then run some commands in the terminal and type, “exit” to end the capturing process.

Now, open the “linuxhint.txt” file.

Output:

The below content is the output of the file linuxhint.txt, which was created by the script command.

1) -c option:

This option is used to get the information of a particular command instead of all commands running in an interactive shell with the file name specified as an argument. After successful execution, the script will exit automatically.

For example, to get a calendar, use:

$ script –c cal linuxhint.txt

Output:

This command will show you the calendar in a txt file.

2) -a Option

This option appends the output to the file while keeping the previous content. The content of both files is separated by a space line.

Take the following command into consideration:

$ script -a linuxhint.txt

Output:

Display the output with the previous running script.

3) -t, –timing[=] Option

This option is used to record terminal operations line by line, which looks like a video. The “scriptreplay” command is used to play back the recorded file.

We need to give a file a name to record the activity. In this example the filename is “linxhint”:

$ script -timing=time_log linuxhint

Output:

To replay the “script” command, use:

$ scriptreplay –timing=time_log linuxhint

4) –force Option

To save the script in some specific directory, use the “–force” option. Run the below force command:

$ script –force /home/aqsa/linux.txt

Output:

5) -e Option:

This option returns the child process, type the below command:

$ script -e linuxhint.txt

In the above image, linuxhint2.txt is the child of linuxhint.txt, and linux.txt is a parent process.

Output:

6) –flush Option

The “-f” or “–flush” options are used to flush the output. It can be used for teleoperation.
Here, the command is:

$ script –flush linuxhint.txt

7) -q quiet Option

The “-q” option hides the message when the script has started and exits:

8) –help Option

This option is used to get help information. It will display all the “script” command related options with one line description:

9) –V/–version Option

This option is used to check the version of “script” command:

Conclusion:

Script is a command-line utility used to get the input and output of all running commands in the text file. It captures all the executed activities in the terminal. Moreover, it prints both input and output in the text file. “Script” command is used to make a copy of executed commands, which should be kept in your notebook and submitted as part of an assignment. Through this post, we have seen the functionality of different “script” options with examples.

Leave A Reply

Your email address will not be published.

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.