Terminal window scrollback is saved somewhere?

Dear Mac enthusiasts,


Every Terminal window has a history, which is evident because you can scroll all the way back. In the Terminal Preferences there is even an option where you can set the Scrollback to unlimited, or limit it to a number of lines.


My question is, is this history saved somewhere in a hidden system file or something like that? Or is it only saved in the Terminal process memory which means when you close the window, or worse, exit Terminal, this history is gone forever?


The practical thing I'd like to be able to do is to access the scrollback info from a Terminal window that has already been closed. I catted (unix command cat) a file, then deleted the file, then closed the window, but I'd like to recover the contents of that file in this way. I know, stupid, but if there is a solution, I'd like to hear it!


Best regards,


Jan

iMac (17-inch Flat Panel), Mac OS X (10.6.8)

Posted on May 27, 2014 8:14 AM

Reply
7 replies

May 27, 2014 10:08 AM in response to Mark Jalbert

I think with the more recent versions of Mac OS X, an application that is being quit, will have its memory saved so that when it is restarted, it can be restored from the same memory so that it looks just like you left it. However, I do not think it there is a separate file. And I'm willing to bet that the saved memory is not something easy to parse just to get the scrollback history out of it.


Then again, if the unlimited scrollback history is checked, I think that IS saved somewhere. However, I know from experience, and the experience of others, that when that unlimited saved scrollback history gets "HUGE", the Terminal performance starts to get really REALLY BAD.


Finally, there is a Terminal -> Shell -> Export Text As... which can be used to save the scrollback history to a file of your choosing.

May 28, 2014 9:36 AM in response to vdbuss

I'm assuming that your account is configured with the standard shell /bin/bash

Under Terminal, if you type the command: history

You get a numbred list of the previous commands entered.


You can get a similar result with the command: cat ~/.bash_history

the contents of .bash_history remains after exiting Terminal.


There is an alternative terminal app called "iTerm" which has a handy Log option under it's Shell menu which logs your current session for a file of your choice. There are many other features iTerm has so I suggest you take a look.

May 29, 2014 4:55 AM in response to vdbuss

The history of your Bash shell commands is kept in ~/.bash_history.


If you want to capture your terminal session and the output from commands, there are a copy of approaches:


  1. Pipe your command to tee(1)
    1. ls -lt | tee myls.log # display on screen and write (overwrite) content to log file
    2. ls -lt | tee -a myls.log # display on screen and write (append) content to log file
  2. Use script(1) to interactively capture command output to logfile
    1. script -t 15 mycmd.log ls -lt
    2. script -t 15 mysession.log
      1. This starts a new capture shell, writes output to the specified logfile
      2. End script session with control-D.

Jun 21, 2014 11:04 PM in response to VikingOSX

Dear VikingOSX,

I created an account and logged in just so say Thanks! The info you gave is golden! In Terminal I tiped open ~/.bash_history and the entire history of anything I've ever typed in Terminal was there. I edited removing mistakes and what I didn't need (as sometimes I need to scrollback and remember the command I used for specific operations) so that is a small "memorandum" id commands if you will.

Once again thanks so much for the useful info provided! 🙂

Jun 22, 2014 7:35 AM in response to S.Fanara

S.Fanara wrote:


Dear VikingOSX,

I created an account and logged in just so say Thanks! The info you gave is golden! In Terminal I tiped open ~/.bash_history and the entire history of anything I've ever typed in Terminal was there. I edited removing mistakes and what I didn't need (as sometimes I need to scrollback and remember the command I used for specific operations) so that is a small "memorandum" id commands if you will.

Once again thanks so much for the useful info provided! 🙂


The history command is history. For instance:


history

history | grep -i cat


You can also use the recall operator and related — all of this is part of how bash works.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Terminal window scrollback is saved somewhere?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.