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
- To record a session and save it to a file named
- To record a session and append it to an existing file named
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
script command comes with several options that can be used to customize its behavior. Here is a table of the available options:
||Append the output to an existing file|
||Run a command and record its output|
||Exit the shell when the script ends|
||Flush output after each write|
||Quiet mode: suppress output to the terminal|
||Add a timestamp to each line of output|
||Print the version number and exit|
||Print a help message and exit|
- 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
-foption to flush the output after each write.
scriptcommand 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 scripton 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.
scriptcommand does not capture mouse events or other graphical output; it only records what appears on the terminal.