script command lets you record and replay activity in your terminal. It’s helpful when you want to create a reference of the steps you’ve taken or you’re creating a tutorial for others to follow.
script outputs a typescript of all the commands you’ve run. It works by dropping you into a sub-shell that logs everything you execute. Your session will be saved as plain text when you leave the shell. This makes
script more reliable than redirected input streams.
script command can be run without any arguments:
A new capturing session will start. Your terminal session will be saved to
./typescript in your working directory. You can specify a different file by giving
script an argument:
Use your shell to execute the command sequence you want to record. When you’re done, press
Ctrl+D or type
exit to drop out of the sub-shell. You’ll return to your main shell session.
Now you can inspect the session log that’s been created:
You’ll see the output from your
script session interspersed with annotations in square brackets. These annotations are used by
script to record details about the terminal itself and the events that occur within it.
As log files are plain text you can freely manipulate them in your favorite editor. Simply cut out any lines you don’t want to retain or that others shouldn’t see.
This is useful if your session inadvertently outputs potentially sensitive information or you want to trim extraneous characters from the log.
script records everything that happens in your terminal, including backspace presses, new lines, and control characters, some of which might not be needed in the final typescript.
script emits the name of the file it’s writing to at the start and end of your session. You can disable this output by adding the
-q flag to enable quiet mode.
SHELL environment variable is read when determining the shell to fork for the inner process. When the variable’s not set,
script will default to
Appending to an Existing File
It’s possible to append new commands to an existing typescript. This lets you “pause” and “resume” recording by exiting your sub-shell and starting a new session.
-a flag to append your commands to the specified file.
script will overwrite the file’s contents when the flag’s not given.
script -a example_session
Adding Timing Data
The basic typescript is ideal when you simply want to record your steps for later reading or sharing.
script can also save timing data alongside its text log. This information can be used to replay your entire terminal session with appropriate delays between the commands.
script with the
-t flag to specify a path to write timings to. Timing files have a two-column format. Each entry contains the elapsed time since the last record in the first column. The second column records the number of characters that were typed, enabling accurate typing speed replays.
script -q -t example_session_timings example_session
scriptreplay command reads typescripts and timing files created by
script. It replays their output into your terminal. The timing data will be used to match the duration of each typed character to its length in your original command sequence.
scriptreplay -t example_session_timings example_session
Some typescripts could contain unwanted delays or run at an uncomfortably slow speed. Use the
-d flag to accelerate the output. All recorded timings will be divided by the number you pass.
# Run 4 times faster scriptreplay -d 4 -t timings typescript
You can also use the
-m flag to cap the maximum delay between individual updates. This lets you specify the longest allowed pause in seconds before
scriptreplay will move to the next command, even if the typescript specifies a longer delay.
# Maximum delay of 2 seconds scriptreplay -m 2 -t timings typescript
Using With Interactive Commands
It’s not recommended to use
script with heavily interactive commands. Terminal text editors, curses-based applications, and dialog prompts are likely to insert polluting garbage characters into your typescript.
script focuses on capturing typical text-based output, not commands that manipulate your terminal to produce a graphical interface.
script isn’t suitable for use with non-interactive shells as its inner shell is always interactive by nature. The command shouldn’t be expected to work with piped input either.
-c flag to
script lets you specify a command. When this mode is used,
script runs the command and captures its output, instead of forking a new interactive shell. This can be more effective at capturing output from some processes that behave differently when not directly connected to a TTY.
-f flag instructs
script to write straight to the session log after each event. This improves safety by ensuring output is captured straightaway.
script manual page suggests this flag could also be used to monitor a user’s terminal in real-time, such as in a teacher and student scenario. The student would run
script -f, then the teacher would use SSH to connect and stream the typescript file live.
script doesn’t usually accept a symbolic link as a typescript path. The
--force flag enables this behavior, instructing
script to resolve hard and soft links to their destination.
script lets you record your terminal sessions to plain text files with accurate timing data. You can inspect, share, and print the typescripts manually, or replay them in your terminal using
The commands are included with most popular Linux distributions. They work with all terminal types but individual typescripts may not replay properly in a terminal that differs from the one used for recording. For best results, run
scriptreplay in the same terminal type you used with
- › How to Make a Fraction in Microsoft Word
- › Check Out This Super-Detailed Teardown of the Google Pixel 7
- › What Is “Shell Infrastructure Host” and Why Is It Running on My PC?
- › Facebook Messenger Is Making a Splash on Windows 11
- › Did You Know iTunes for Windows Supports AirPlay, Too?
- › Get a Gift Card and Save Up to $25 With These TurboTax Deals