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.
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.
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.
Example 2: To start the typrscript, run any random command and save it in a text file, let’s say geeksforgeeks.txt.
The output produced above is the content of the file geeksforgeeks.txt, created by script command.
- -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.
- -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.
- -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 telecooperation
- –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.
- -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.
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
- -V, –version: Output version information and exit.
- -h, –help: Display this help and exit
- rev command in Linux with Examples
- rcp Command in Linux with examples
- apt-get command in Linux with Examples
- sum command in Linux with Examples
- cvs command in Linux with Examples
- until command in Linux with Examples
- Cat command in Linux with examples
- cc command in Linux with Examples
- id command in Linux with examples
- w command in Linux with Examples
- tee command in Linux with examples
- dc command in Linux with examples
- ip command in Linux with examples
- gs command in Linux with Examples
- tty command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.