Any way to enable scrollbacks after you quit the window? Even if the app itself is still running, closing the window and opening a new one doesn't work.

I am SURE it used to work on my old Mac, but I simply cannot find an option in preferences anywhere and Google is not my friend.

  • Before Mac OS X Lion 10.7, Terminal had no facility for saving/restoring the scrollback after you close a window. Are you talking about the scrollback log (i.e., the text that has scrolled off the top of the terminal screen) or the shell command history? (e.g., in bash, run the "history" command and you'll see the recorded command history.) – Chris Page Aug 19 '11 at 10:50
  • Was your "old" Mac running Mac OS X Lion 10.7 or was it using an earlier version of Mac OS X? – Chris Page Aug 20 '11 at 20:47
  • Nope. Same version - never used Lion. – Dan Aug 22 '11 at 7:54
  • 1
    @Chris_Page - I'm using a non Lion Macbook Pro side by side right now which happily scrolls back through all prior history even after a Cmd + Q quit. I am not questioning your OS knowledge here, for all I know that may not be a built in feature, but I've had that Mac from new, never enabled anything consciously to add that feature. So it's possible, and I can prove it, but have no idea how to enable it on a mac running the identical OS. – Dan Aug 29 '11 at 7:44
  • 1
    SL 10.6.8 B10K549 - Terminal 2.1.2 (273.1). Improbable, not impossible. :-) I mean from a technical perspective, this is not a big leap to store some scrollbacks in non volatile memory, and Lion's proved it, not that it needed to be proved. For me, it's always just worked so I've never questioned why it might not be there. My new machine is corporate, so I assumed it was a security feature enabled to admin in case the laptop got stolen. – Dan Aug 29 '11 at 10:31

I had the same issue on my new Mac, when I checked the history file ~/.bash_history I discovered that it was owned by root. I run sudo chown username .bash_history, now when I reopen terminal my history is preserved.


Assuming you have not modified the default behaviour in any way, you should be able to scroll through a list of your previous commands simply by hitting the up cursor key. There are so many alternatives depending on what shell you are using if you have changed the defaults etc, so that would be useful info. Also, what OS are you on, from Lion onwards Terminal reloads the last 500 lines out output even from the last closed screen on restart.

  • Stock install, Snow Leopard 10.6.8, standard Terminal app. Scrollback is set unlimited. The more I think about it the more I think this might be a security feature as this is a corporate machine. Anywhere else I might change the default behaviour? – Dan Aug 18 '11 at 10:49
  • When you start a shell, you can give it options for this sort of thing. For example "bash -o vi" or "ksh -o vi" will start either a Bash or Ksh shell with command history using the standard VI commands, which is K to go back in your history, and J to move forwards. This will tweak the other options for moving left/right also to use H and L instead of the cursor keys, but this isn't default behaviour although it ay be stop gap until you fix it. For sure the default is to allow this, so you may be a tweaked setup in one way or another. – stuffe Aug 18 '11 at 10:58
  • Correction: Terminal restores the last 10,000 lines of scroll back log by default (not 500), in addition to the screen contents. – Chris Page Aug 19 '11 at 10:34
  • 1
    The amount of scrollback restored can be controlled with defaults write com.apple.Terminal by setting RestoreScrollbackLines (or you can set ShouldLimitRestoreScrollback to NO to save/restore all the text). – Chris Page Aug 19 '11 at 10:43

If your Terminal is losing the history (previously entered commands), try this:

Check first, in your home directory, who owns the file .bash_history:

ls -al .bash_history

If for some reason the file is not owned by your username, will appear (for example) in the listing as:

-rw-------    1 root      staff       32 Jul 11  2011 .bash_history

Fix it with:

sudo chown [username] .bash_history

(source: http://www.paulmc.org/2009/01/enable-bash-history-in-terminal/ )

Now close Terminal, open it again and you should be capable of seeing previously entered commands by pressing the up arrow (that is, if you're using bash as your Terminal shell - - the default).

  • 1
    Or just rm ~/.bash_history, it will get recreated when you start the next bash. – nohillside Oct 12 '12 at 21:00

As far as I know, the scrollback history is discarded when a window is closed; there is no way to reopen a window that you closed to review its scrollback history. There is, however, a preference setting that lets you configure “one last chance” to review or save the scrollback history after you exit a window’s initial shell (I am not sure if this matches what you mean by “after you quit the window”).

In 10.6, this preference setting is in Terminal’s preferences (the Terminal > Preferences… menu item, or its shortcut: ⌘,) under the Settings section in the Shell tab of your “settings set” (probably named Basic, look for the one with the word “Default” under its name). The preference is labeled “When the shell exits:”.

Screen shot of Terminal preferences window showing the “When the shell exits” options.

The available options are

  • Close the window

    The window will always disappear immediately after you exit the shell.

  • Close if the shell exited cleanly

    The window will be closed immediately (as above) if the shell gives a exit code of zero (“exited cleanly”).
    The window will remain open (see below) if the shell gives a non-zero exit code.

  • Don’t close the window

    The window will always stay open when you exit the shell; the line [Process completed] will be appended to contents of the window.
    To close the window you must use

    • the Shell > Close Window menu item (Shell > Close Tab for a tab), or
    • ⌘W (the menu item’s shortcut), or
    • the red close button in the title bar (the x button in the tab for a tab).

This is controlled globally by enabling System Preferences -> General -> Restore windows when quitting and re-opening apps.

  • Lion's Resume feature doesn't affect whether shells save/restore the command history. – Chris Page Aug 19 '11 at 10:35
  • The question appears to be about the Terminal scrollback buffer (which is affected by the described setting), not the command history. – Ingmar Hupp Aug 19 '11 at 13:17
  • Yes, the question is misleading: "previous commands" should probably be "the scrollback log". On the other hand, the originator says it used to work on an "old Mac", but prior to Lion there was no facility in Terminal to restore the scrollback. If this really is about the scrollback log, my only guess is that they were using a program like screen to restore the scrollback, or they were using some other terminal program. Or, "old Mac" merely means a different machine running Lion, not an "old machine running an older OS version". – Chris Page Aug 20 '11 at 20:46
  • Yes I am talking about scroll back. Old Mac is a pre unibody Macbook pro running latest version of Snow Leopard. Scrolback doesn;t work on new mac no matter what I do re: the above tips. – Dan Aug 24 '11 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .