Fundamentals 7 min read

How to Record and Replay Terminal Sessions with the Linux script Command

This guide explains how to use the Linux script command to capture terminal output, customize log file names, collaborate by sharing recordings, and automatically record remote assistance sessions, providing step‑by‑step examples and useful options for low‑memory environments.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Record and Replay Terminal Sessions with the Linux script Command

Why record terminal sessions?

When debugging applications that generate large amounts of log data—especially on low‑memory or embedded systems—manual copy‑paste becomes impractical. While tools like SecureCRT and MobaXterm can save logs, many terminals (e.g., PuTTY) lack this feature. The script utility solves this problem by recording everything displayed in the terminal.

Typical use cases

Debugging applications that produce massive logs and need the output saved locally for later analysis.

Collaborating with teammates: record half‑finished work, share the file, and let a colleague continue from the same point.

Allowing remote assistance while keeping an audit trail of the helper’s actions.

Basic usage of script

Running script without arguments creates a file named typescript in the current directory and records all subsequent terminal activity.

The file is plain text and can be opened with any editor. To stop recording, press Ctrl+D or type exit. The file size grows only after the command exits.

[alvin@VM_0_16_centos test]$ script
Script started, file is typescript
[alvin@VM_0_16_centos test]$ echo hello
hello
[alvin@VM_0_16_centos test]$ ls
... (file list) ...
[alvin@VM_0_16_centos test]$ exit
exit
Script done, file is typescript

Specifying a custom file name or location

Provide a filename (or path) after the command:

[alvin@VM_0_16_centos test]$ script ~/alvin-script
Script started, file is /home/alvin/alvin-script
... (session) ...
Script done, file is /home/alvin/alvin-script

Collaborating with colleagues

Record your work, send the typescript file, and the recipient can view the progress. To let the colleague continue recording in the same file, use the append option -a:

[alvin@VM_0_16_centos test]$ script -a cooperate-job
Script started, file is cooperate-job
... (your commands) ...
Script done, file is cooperate-job

Automatically recording remote assistance sessions

Add a script invocation to .bash_profile so it runs whenever someone logs in. Example entry:

vim ~/.bash_profile
# Append at the end:
/usr/bin/script -qa /path/to/record-file

The -q flag makes the recording silent, so the remote user does not see a prompt. Without -q, the user sees the usual login banner followed by “Script started…”.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

loggingShellCollaborationscriptterminal
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.