script

Record a terminal session exactly as it appears, including input and output.

Category: System terminal logging audit debugging

Install

# Usually part of util-linux

# RHEL / Alma / Rocky
sudo dnf install util-linux

# Debian / Ubuntu
sudo apt install bsdutils util-linux

# openSUSE
sudo zypper install util-linux

# Arch
sudo pacman -S util-linux

What it does

script records everything printed to a terminal session and saves it to a file. It captures both commands typed and their resulting output, making it useful for auditing, documentation, debugging, or training.

How it works (mechanical)

  • Creates a pseudo-terminal (pty) session.
  • Spawns a new shell inside that session.
  • Logs all input and output to a file (default: typescript).
  • Ends recording when you exit the shell.
  • Optional timing file can be used with scriptreplay.

Quick Start

# Start recording (default file: typescript)
script

# Exit the subshell to stop recording
exit

10 Practical Examples

# 1) Record session to a specific file
script session.log
# 2) Append to an existing log
script -a session.log
# 3) Record with timing file for replay
script -t timing.log session.log
# 4) Replay recorded session (with timing)
scriptreplay timing.log session.log
# 5) Record only output (suppress command echo)
script -q session.log
# 6) Automatically run a command and exit
script -c "ls -l /etc" output.log
# 7) Use for troubleshooting a service setup
script troubleshoot.log
sudo systemctl status httpd
exit
# 8) Record installation steps for documentation
script install_steps.log
# 9) Check the resulting file
less session.log
# 10) Verify terminal type inside script
echo $TERM

Notes & Gotchas

  • Captures everything, including passwords typed (be cautious).
  • Control characters and formatting are preserved.
  • Default filename is typescript if none specified.
  • May not perfectly reproduce interactive programs on replay.
  • Use secure storage for logs containing sensitive data.

Historical Context

script has long been part of Unix systems for session logging. It provided a simple way to capture terminal activity before advanced centralized logging and auditing tools were common.

Modern Equivalent

While script remains widely used, modern systems may rely on session recording tools, audit frameworks, or centralized logging platforms. However, script remains simple and highly effective for local recording.

Related Commands

  • scriptreplay — replay recorded sessions.
  • tty — display current terminal device.
  • who — show logged-in users.
  • history — show shell command history.
  • tee — write output to both screen and file.