script – Log all operations of a terminal session

The script command is a utility that records everything that appears on the terminal, including input/output, timestamps, and other relevant information. It is useful for auditing, debugging, and training purposes.


To start recording a terminal session, simply type script followed by the name of the output file. For example, script mysession.log. From this point on, all the commands and their output will be saved in the specified file. When you’re done, type exit or press Ctrl-D to stop the recording.

Here are some examples of how to use script:

  • To record a session and save it to a file named mysession.log:
    script mysession.log
  • To record a session and append it to an existing file named mysession.log:
    script -a mysession.log
  • To record a session and specify a custom timestamp format:
    script -t 2> mysession.log
  • To record a session and suppress the output to the terminal:
    script -q mysession.log


The script command comes with several options that can be used to customize its behavior. Here is a table of the available options:

Option Description
-a Append the output to an existing file
-c Run a command and record its output
-e Exit the shell when the script ends
-f Flush output after each write
-q Quiet mode: suppress output to the terminal
-t Add a timestamp to each line of output
-V Print the version number and exit
--help Print a help message and exit

Troubleshooting tips

  • If you encounter permission errors when trying to write to the output file, make sure you have the necessary permissions to write to that location.
  • If the output file is empty or incomplete, try running the command with the -f option to flush the output after each write.


  • The script command is not available on all Linux distributions by default. If it is not installed on your system, you can usually install it using your package manager (e.g. sudo apt-get install script on Debian/Ubuntu).
  • The output file can become quite large if the session is long or there is a lot of output. Make sure you have enough disk space available before starting a recording.
  • The script command does not capture mouse events or other graphical output; it only records what appears on the terminal.