4

I'm using Mac 10.9.5. When I run a terminal with multiple tabs (using bash shell), I've noticed that when my computer restarts, the terminal will open up with the same number of tabs that were open in the previous session, but the commands I was running in the previous session (accessible via the "history" shell command) are no longer present in each tab.

Is there a way to preserve each session's history in the appropriate tab between computer restarts?

1

Try adding this to ~/.bash_profile:

HISTFILE=~/.bash_history.$(basename $(tty))

This creates a unique history file for the terminal associated with each tab.

  • Already covered here. – mtklr Jul 7 '15 at 2:23
-2

The command history is saved by the shell when it closes, and by default this goes into ~/.bash_history.

So as the shell in each of your tabs is closed, they each append their own command history to that file. When new shells/tabs are opened, they will load that file for their history.

So in a sense, each tab's history is saved, and you should be able to use ctrl-R to search for it (within limits of the history size limit), but when reloaded, each tab will see all the history, and in blocks corresponding to the order the previous tabs happened to close.

You might be able to configure the bash history more to your liking.

  • 1
    The answer should be based around the information in the link telling the OP how to preserver the session's history. The other info is a good explanation of what the history does but does not answer the question asked – Mark Jul 6 '15 at 21:32

You must log in to answer this question.

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