Skip to content

script Linux command

The Linux script command is used to record all activities in a terminal session. It captures both input and output, including error messages. This can be useful for troubleshooting, auditing, or training purposes. The recorded session is saved in a file that can be reviewed later. The script command can be invoked with various options to customize the recording behavior. It is a handy tool for tracking changes made during a session and can help in recreating sequences of commands.

Terminal window
grep [options] [pattern] [file]
OptionDescription
-i, —ignore-caseIgnore case distinctions
-v, —invert-matchInvert the sense of matching
-n, —line-numberPrefix each line with line number
-c, —countSuppress normal output; instead print a count of matching lines
-r, —recursiveRead all files under each directory, recursively
-w, —word-regexpSelect only those lines containing matches that form whole words
-l, —files-with-matchesSuppress normal output; instead print the name of each input file from which output would normally have been printed
-h, —no-filenameSuppress the prefixing of filenames on output
-q, —quietQuiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected
-E, —extended-regexpInterpret pattern as an extended regular expression
ParameterDescription
patternThe pattern to search for in the file(s)
fileThe file or files to search for the pattern in
Terminal window
script session.log

Starts recording a shell session and saves the output to a file named “session.log”.

Terminal window
script -t 2>session_timing.log session.log

Records a shell session with defined timestamps and saves the output to “session.log” while timestamps are saved to “session_timing.log”.

Terminal window
exit

Stops recording a shell session started with the “script” command.

Terminal window
script -a session.log

Appends the output of a new shell session to an existing file named “session.log”.

Terminal window
script custom_session.log

Records a shell session and saves the output to a custom file named “custom_session.log”.

Terminal window
script -f session.log

Starts recording a shell session in a new pseudo-terminal and saves the output to “session.log”.

To use the script command in Linux, execute the following command:

Terminal window
script --option <value>

How can I save the output of a script command to a specific file?

Section titled “How can I save the output of a script command to a specific file?”

To save the output of a script command to a specific file, use the following command:

Terminal window
script -a output.log

How do I include timestamps in the output of a script session?

Section titled “How do I include timestamps in the output of a script session?”

To include timestamps in the output of a script session, you can use the following command:

Terminal window
script -t 2>output_with_timestamps.log

How can I start a script session with a custom shell?

Section titled “How can I start a script session with a custom shell?”

To start a script session with a custom shell, you can specify it in the command like this:

Terminal window
script -c "bash --norc" output_custom_shell.log

How do I append the output of a script session to an existing file?

Section titled “How do I append the output of a script session to an existing file?”

To append the output of a script session to an existing file, you can use the following command:

Terminal window
script -a existing_output.log

How can I log the entire script session, including all input and output?

Section titled “How can I log the entire script session, including all input and output?”

To log the entire script session, including all input and output, you can use the following command:

Terminal window
script -f full_session.log

How do I specify the maximum time for a script session to run?

Section titled “How do I specify the maximum time for a script session to run?”

To specify the maximum time for a script session to run, you can use the following command:

Terminal window
script -c "timeout 10s bash" output_timeout.log

How can I disable the echoing of commands in the output of a script session?

Section titled “How can I disable the echoing of commands in the output of a script session?”

To disable the echoing of commands in the output of a script session, you can use the following command:

Terminal window
script -q output_no_echo.log
  • Recording terminal sessions
  • Creating logs of terminal commands and outputs
  • Troubleshooting and debugging sessions
  • Reproducing and sharing command sequences
  • Monitoring and reviewing user interactions with the terminal