save terminal history linux

How to Save All Terminal Output to File

Sometimes you may need to save all terminal output to file. This is a basic requirement but many beginners may not be aware that most Linux systems already provide a simple tool called ‘script’ that allows you to record all terminal outputs. In this article, we will learn how to save all terminal output to file.

How to Save All Terminal Output to File

Script utility tool basically saves everything printed on your terminal during the script session. It comes pre-installed on most Linux systems. You can get more details about script command using man.

$ man script

You can start a script session by entering script, followed by the filename where you want to store subsequent terminal outputs. Here is an example to start a script session.

$ script out.txt
Script started, file is out.txt

All commands and their terminal outputs, after you enter the above command, will be saved to out.txt file. If you don’t specify any filename after script command, then it will store all commands and their terminal outputs in file named typescript.

Now let us say, that after you start script session, you enter the following command, and get the output shown below.

$ ls
file1.txt file2.txt

To exit the script session, enter exit command.

$ exit
Script done, file is out.txt

Now if you view the contents of out.txt file you will see the ls command as well as its output.

$ cat output.txt

Script started on Mon 20 Apr 2021 08:00:14 AM BDT
$ ls
file1.txt file2.txt
$ exit

Script done on Mon 20 Apr 2021 08:00:21 AM BDT

As you can see, it is stores all commands and terminal output after script command was called, including the exit command and its output.

script command offers many useful options such as -q for quite mode. In this case, it will not show any program messages.

You can use man script command to get more details about it. script is a useful command to save terminal history.

Also read:

How to Remove Startup Applications in Ubuntu
How to Do Port Forwarding in Raspberry Pi
How to Install Raspbian in Raspberry Pi
How to Configure LDAP Server in Ubuntu
How to Install SSL Certificate in Raspberry Pi

Leave a Reply

Your email address will not be published.