Open In App
Related Articles

script command in Linux with Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

script command in Linux 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 exit. By default, all the terminal information is saved in the file typescript , if no argument is given. script is mostly used when we want to capture the output of a command or a set of command while installing a program or the logs generated on the terminal while compiling an opensource codes, etc. script command uses two files i.e. one for the terminal output and other for the timing information. 

Syntax:

script [options] [file]

Example 1: To start a typescript without any argument. If no filename is given as argument, script will automatically create a file namely typescript in the home directory to save the recorded information. 

Input:

  

In order to stop the typescript, we just need to execute exit command and script will stop the capturing process. Since there’s no filename given as argument, the script will automatically create a file namely typescript in the home directory to save the recorded information. 

Output

Example 2: To start the typescript, run any random command and save it in a text file, let’s say geeksforgeeks.txt

Input

 

Output

The output produced above is the content of the file geeksforgeeks.txt, created by script command. 

Options:

  • -a, –append: This option is used when we want to append the output, retaining the prior content of the file. The multiple contents get separated by adding a line that states the date and time of the script started. 
    Example: 
    Input:
      
    Output
  • -c, –command: This option is used when we want to run a particular command rather than interactive shell and get terminal information in the file given as argument or typescript by default. The script will automatically exit after successful execution. 
    Example: To get the typescript of cal command. 
    Input:
      
    Output
  • -e, –return: This option simply return exit code of the child process.
  • -f, –flush: This option is used to run flush output after each write. It’s useful for tele-cooperation.
  • –force: This option allows default output file i.e. typescript to be hard or symbolic link. 
    Example: To capture terminal activity in a file let’s say gfg2 that is stored in /home/sc.
     Input

    Output
  • -q, –quiet: This option does not display the notification stating that the script has started and quietly execute and exit the script command. 
  • -t, –timing[=]: This option allows user to capture the terminal activity step by step and appears like a video when the recorded file is executed with the help of scriptreplay command. 
    Example: To capture terminal activity in a manual file, geeksforgeeks1
    Input

     This option contains two data fields. The first field indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time. Now let’s check the output created using another command i.e. scriptreplay as follow:
scriptreplay --timing=time_log geeksforgeeks1

             Output:

  • -V, –version: Output version information and exit. 
  • -h, –help: Display this help and exit 

Last Updated : 23 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads