How to record terminal session

Maybe it is rarely needed, but recently, I found it very useful to know how to record an interactive session, so I could reference to it later or just examine it further.

The whole process is very simple, as it requires only script utlity from bsdutils package. This package is installed by default, so you can use it everywhere.

Basic usage

The script utility will start an interactive shell defined using SHELL variable and store operations in ~/console.log file.

$ script ~/console.log
Use CTRL+D shortcut or exit command to stop recording.

Use -a or --append argument to append output to the specified file instead of truncating it.

$ script -a ~/console.log

Use -f or --flush argument to flush output after each write.

$ script -f -a ~/console.log

Store operations and replay them later

Use -t or --timing argument to store timing data.

$ script -tconsole.timings console.commands
Please notice that there is no space between argument and filename.

Replay operations using scriptreplay utility.

$ scriptreplay console.timings console.commands 

Additional notes

Please read script and scriptreplay manual pages and documentation available in /usr/share/doc/bsdutils/README.script file.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland