I'd like to be able to look through my command history (all the way back to the beginning of the user).
Is there any guarantee that .bash_history will continue to be appended to?
If there is a limit where the file will start to be truncated (hopefully from the beginning) is there a way to remove that limit?
man bash
is your friend: TheHISTFILESIZE
variable:Adam suggested that unsetting size limits doesn't cut it, but you can avoid other instances of shell to change HISTSIZE, HISTFILESIZE, ... by setting readonly flag on them in /etc/profile.
Also note. By default if you work with multiple login sessions (I usually 2 or 3 putty windows logged into the same server), they do NOT see eachothers history.
Also it appears that when I exit all the shells its the last one to exit is the one which is saved back the file (i.e. is visible when I start work the next day). So I assume bash is keeping the history in memory and then flushes to the file on exit, at least thats my guess based on what I see.
If you want all commands from all sessions appended to the history instantly (so that you can use commands from one session immediately in another), you can put the following lines into your .bashrc :
More information about these commands can be found here: Preserve bash history in multiple terminal windows
There is a number of environment variables that control how history works in bash. Relevant excerpt from bash manpage follows:
To answer your questions directly:
No there isn't a guarantee, since history can be disabled, some commands may not be stored (e.g. starting with a whitespace) and there may be a limit imposed on the history size.
As for the history size limitation: if you unset
HISTSIZE
andHISTFILESIZE
:you'll prevent the shell from truncating your history file. However, if you have an instance of a shell running that has these two variables set, it will truncate your history while exiting, so the solution is quite brittle. In case you absolutely must maintain long term shell history, you should not rely on shell and copy the files regularly (e.g. using a cron job) to a safe location.
History truncation always removes oldest entries first as stated in the manpage excerpt above.