1

Are they logged anywhere? Where do the stdout go after the terminal dies? I'm aware I could easily save it as it runs, but sometimes we just realize we need it when the terminal is gone.

5

Nope, once a terminal is gone the output is also gone. Some of it may still linger for a while in RAM, some may have been saved to logs due to various logging setup, but essentially it's lost. This is intentional. If the information was logged it would quickly fill up your disk (the characters really mount up if you use the shell for everything), and it would likely contain at least some confidential information. I once tried setting the GNOME Terminal scrollback buffer to unlimited. Soon afterwards my machine started slowing to a crawl. The terminal was using all my RAM!

You could set up some fancy logging by using something like exec > /tmp/stdout.log 2> /tmp/stderr.log in your ~/.bashrc (untested) and for example logstash to rotate your logs, but it would still have the fundamental problem of keeping confidential information around for a while.

What most people do instead is to rely on the shell's history file, for example ~/.bash_history, which stores the commands so that you can reproduce the result.

  • I get the the wiping confidential information part. But couldn't a tmp file be limited in size, and just store the last 1,000 messages? – Pierre B Jun 10 '17 at 17:25
4

Use script ~/terminal_logs/$(date +%Y%m%d-%H%M%S)-$(tty)-$$.log in your terminal on login. This saves your session in a file named from the date and time the shell was started, the terminal and the shell process ID.

Edit: Thanks to Gilles for the format string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.