Save All the Terminal Output to a File – Linux

In Linux terminal you can save not only an output of the individual commands using different types of redirections, but you can also capture and save to a file all the commands executed during a session and their output.

All the commands executed in a Linux terminal and their output can be saved to a file using a script command.

The script command creates a session during which it saves everything displayed on a terminal to a specified file.

In this short note i am showing how to save all the terminal output to a file in Linux using the script command.

Save All the Terminal Output to a File

Start a script session to save all the terminal output to a file named output.txt in the current directory:

$ script output.txt

Execute some commands which outputs you want to save:

$ uptime
$ uname -a

Stop the script session:

$ exit

Now if you open the output.txt you should see all the captured commands with their output:

$ cat output.txt
-- output --
Script started on 2021-11-23 18:38:56+01:00 [TERM="xterm-256color" TTY="/dev/pts/0"...
user@box ~ $ uptime
 18:39:05 up 1 day,  1:09,  1 user,  load average: 1,01, 1,07, 0,97
user@box ~ $ uname -a
Linux box 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_6...
user@box ~ $ exit
exit

Leave a Reply