script Command Examples in Linux

The “script” command in Linux is used to record all the terminal input and output in a file. This can be very useful for keeping a record of your work, for sharing or reviewing later, or for debugging purposes.

To use the “script” command, simply open a terminal and type “script filename” where “filename” is the name of the file you want to save the output to. The script command will then start recording everything you type and all the output that appears on the terminal, until you stop it by typing “exit”.

script Command Examples

1. Start recording in file named “typescript”:

# script

2. Stop recording:

# exit

3. Start recording in a given file:

# script logfile.log

4. Append to an existing file:

# script -a logfile.log

5. Execute quietly without start and done messages:

# script -q logfile.log

Note

Note that the “script” command can also be used with the “-a” option to append the output to an existing file, instead of overwriting it. Additionally, the “script” command can be used with the “-c” option to run a single command and record its output, without starting a new shell.

Related Post