script
Record terminal sessions to a file
TLDR
Record a new session to a file named typescript in the current directory
Stop recording
Record a new session to a custom filepath
Append to an existing file
Record timing information (data is outputted to stderr)
Write out data as soon as it happens
Execute quietly without start and done messages
SYNOPSIS
script [options] [file]
PARAMETERS
-a
Append the output to file or to typescript, retaining the prior contents. Without this option, script will overwrite the file.
-c command
Run the specified command instead of an interactive shell.
-f
Flush output after each write. Useful for recording in real-time.
-q
Run in quiet mode, suppressing the start and done messages.
-t
Output timing data to standard error. The output consists of pairs of values, the first representing the time since the start of the script command in seconds, and the second representing the number of characters output at that time.
file
The file to store the typescript in. If omitted, 'typescript' is used.
DESCRIPTION
The script command in Linux is used to make a typescript of everything printed on your terminal. It captures all input and output, including commands you type, their output, and any system messages. This is useful for creating logs of terminal sessions, debugging purposes, or archiving command-line interactions. The output is saved in a file, typically named typescript (though this can be changed using an argument to script). You can then review this file to see exactly what happened during the session. The recorded file can be viewed using a standard text editor or other text processing tools.
The command is quite straightforward. Starting script initializes a new recording session, and exiting the shell (typically with exit or Ctrl+D) stops the recording. During the session all terminal interaction is appended to the specified output file. Script's utility lies in providing a faithful log of a command line session, allowing for review, reproduction, or reporting of terminal-based activities.
CAVEATS
The script command captures raw terminal output, which may include control characters and formatting. This means the output file may not be directly readable without processing. Also, some programs might behave differently when their output is piped to script.
EXIT STATUS
The exit status of script is the exit status of the shell or command that was recorded. If the shell exited normally, script will also exit with code 0. If it exited due to a signal, script will exit with 1 + the signal number.
EXAMPLES
- To start a recording session, simply type script.
- To specify the output file, type script mylog.txt.
- To run a specific command and record the output: script -c "ls -l" mylog.txt.
HISTORY
The script command has been a part of Unix-like systems for a considerable time. Its primary purpose has consistently been to record terminal sessions. Its development has been focused on providing a simple and reliable way to capture terminal I/O for documentation, debugging, and logging. It remains a standard tool in many distributions due to its straightforward function and broad utility.