Issue
I know that I entered a command the other day, but now I can't find it using history
or .bash_history. Any ideas why this happens? I suspect it has to do with using multiple tabs in my OS X terminal, and somehow the history doesn't carry over between tabs, but I don't know.
Solution
As of OS X El Capitan 10.11, by default Bash is configured to save separate command histories for each terminal, so they can be restored separately for Resume.
Each individual history is also appended to the global history in ~/.bash_history when the shell is exited. If you quit Terminal and then re-open it—with or without Resume enabled—you should find that commands from every terminal are in ~/.bash_history. If you have Resume enabled, each restored terminal will only contain its restored history, but when you create a new terminal it will start with the latest global history.
Because all the command histories are appended to the global ~/.bash_history file, you may wish to increase the number of commands stored by setting the HISTFILESIZE
environment variable so the latest terminal histories don't push the other terminal histories out of the file too soon. The default value is 500. I have mine set to 10,000. I also set HISTSIZE
to 10,000 so I can navigate through the entire history (otherwise, only the last 500 will be read from the history file).
The script that arranges for separate command histories is in /etc/bashrc_Apple_Terminal
in OS X El Capitan 10.11 and later. It contains extensive comments describing how the mechanism works, and how to customize or disable it.
Answered By - Chris Page