Ubuntu – bash shell output history file location

bashcommand linehistoryoutput

Where does the bash shell store the actual terminal session? I want to read the output of commands I used before. All I can find googling is how to store the output of a command.

Since output is displayed on the screen, it has to be stored somewhere anyway. So my question is: where?

Best Answer

Bash only stores history of the commands you ran (which you can retrieve by typing history). Unless you already have set the scroll-back to a very high number, there is no way to see the outputs that are older than the set value of scroll-back. Also setting this value to a very high number will make your scrolling sluggish since the lines are stored in the memory.

To store your future commands and their outputs, there are few options:

Using screen

Start a screen session by entering screen. Once you are inside screen, press Ctrl-a, then :, then enter log. All the I/O will be captured in screenlog files in the directory where you started the screen command.

Using script

You can start by typing script. A script session will start that will capture all the I/O to a file named typescript. You can exit the script session by Ctrl-d and view the logs in the typescript file.

Using tee

tee is a handy tool. You can do something like this:

$ bash | tee log.txt

This will open a new bash shell inside the one you are already running. When you exit out of this, you can see the outputs in the file called log.txt

Other ways

As Dustin Kirkland suggested in this post, you can also use byobu. Although, I have never used, terminal screencasting tools such as Shelr also sounds like an option.