bash shell output history file location

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.


There are lots of questions related to this one, but they all start with the (right) assumption that the output isn't logged.

So my question is: where?

Nowhere: Bash's (and any other shell that I know of's) output isn't logged.

Since output is displayed on the screen, it has to be stored somewhere anyway.

It is, but most likely not in plain text and not even on the disk (although this really is up to the terminal emulator): most likely, and at least in most cases, in a memory segment allocated by the terminal emulator.

However for sure it isn't logged to a file, at least not by the shell, and I don't know of terminal emulators which log the output to a file by default.

Indeed this doesn't mean it's impossible to log the terminal output: first I'll mention something that I think not many are aware of, since I've never saw anyone mentioning this at least here on Ask Ubuntu: Konsole allows to save the scrollback to a file (perhaps there are other terminal emulators that provide such a functionality, Konsole is just the only one I know of), although this is limited by Konsole's scrollback size limit.

This is often not really useful though, and most likely you'll want to look into "proper" solutions to log a whole session's output to a file (How do I log all input and output in a terminal session? and Ron's answer).