script

script linux command cheatsheet by Thamizhiniyan C S

Introduction

script command makes a typescript of everything on your terminal session. The terminal data are stored in raw form to the log file and information about timing to another (optional) structured log file.


Syntax

script [options] [file]


Important Flags

FlagDescription

-I, --log-in

log stdin to file

-O, --log-out

log stdout to file (default)

-B, --log-io

log stdin and stdout to file

-T, --log-timing

log timing information to file

-t[], --timing[=]

deprecated alias to -T (default file is stderr)

-m, --logging-format

force to 'classic' or 'advanced' format

-a, --append

append to the log file

-c, --command

run command rather than interactive shell

-e, --return

return exit code of the child process

-f, --flush

run flush after each write

--force

use output file even when it is a link

-E, --echo

echo input in session (auto, always or never)

-o, --output-limit

terminate if output files exceed size

-q, --quiet

be quiet

-h, --help

display this help

-V, --version

display version


Examples

CommandDescription
script

To start a typescript without any argument. If no filename is given as argument, script will automatically create a file namely typescript in the home directory to save the recorded information.

script mysession.log

This command starts a new recording session, with the output stored in the 'mysession.log' file.

script $(date '+%d-%m-%Y')_session.log

This command records the terminal session and saves the output into a file with the current date as part of the name.

exit

In order to stop the typescript, we just need to execute exit command and script will stop the capturing process.

script -a -f filename.txt

To start the typescript, run any random command and save it in a text file, let’s say filename.txt.

script -c "cal"

To get the typescript of cal command.

script -c 'ls -la' directory_listing.log

This command runs 'ls -la' and records its output into 'directory_listing.log' file.

script -c 'ls -la' | tee file.log

This command runs 'ls -la', displays its output and simultaneously saves it into 'file.log'.

script -f

This option is used to run flush output after each write.

script --force

This option allows default output file i.e. typescript to be hard or symbolic link.

script -h

Display this help and exit.

script -q

This option does not display the notification stating that the script has started and quietly execute and exit the script command.

script -t timing_file.txt

This option allows user to capture the terminal activity step by step and appears like a video when the recorded file is executed with the help of scriptreplay command.

scriptreplay --timing=time_log geeksforgeeks1

To replay the captured terminal activity.

script -V

Output version information and exit.

Last updated