22
3
For some reason, I cannot get my system to keep my BASH history after a reboot. Here are the relevant sections of my ~/.bashrc
:
shopt -s histappend
PROMPT_COMMAND='history -a; updateWindowTitle'
export HISTCONTROL=ignoredups
export HISTSIZE=9999
export HISTFILESIZE=999999
export HISTFILE="$HOME/.bash_history"
As far as I can tell those are all the necessary options (I know I used to be able to keep history across multiple reboots without all of these in the past). However, despite having added these options several reboots ago, I still loose most of my history after a reboot. It is not empty, but it does not have the 9999 lines I had before rebooting.
Before anyone complains, yes I have read these questions. I have implemented some of their suggestions as listed above, the rest were either unhelpful or not relevant:
- Bash history loss when using histappend
- How to prevent Bash from altering history?
- What determines what shows up in the bash history command?
- How do I keep my bash history across sessions?
- save bash history, regularly
On the off chance that there may be other relevant commands in there, you can view my entire ~/.bashrc
here.
So, what am I missing? Why is my history not saved? If anyone thinks another file may be relevant let me know and I'll post it. I checked by running grep -i hist \.*
in my $HOME
which showed that the only relevant .
file containing the string hist
or HIST
was .bashrc
.
I am running Linux Mint Debian Edition, GNU bash, version 4.2.36(1)-release (x86_64-pc-linux-gnu) and my favorite terminal emulator (in case that's relevant) is terminator
.
UPDATE:
Following @mpy's suggestion in the comments, I changed my ~/.bashrc
to set HISTFILE=~/bash_history
as opposed to the default ~/.bash_history
and that seems to solve the problem for interactive shells. Login shells still display the same behavior, with the history truncated at 500
lines. However, there are no HIST
related variables set in the relevant files:
$ for f in /etc/profile ~/.profile ~/.bash_profile ~/.bash_login; do \
echo -ne "$f :"; echo `grep HIST $f`; \
done
/etc/profile :
/home/terdon/.profile :grep: /home/terdon/.profile: No such file or directory
/home/terdon/.bash_profile :grep: /home/terdon/.bash_profile: No such file or directory
/home/terdon/.bash_login :grep: /home/terdon/.bash_login: No such file or directory
$ grep -r HIST /etc/profile.d/ <-- returns nothing
So, why is setting HISTSIZE
and HISTFILESIZE
in the ~/.bashrc
not enough unless I explicitly set the $HISTFILE
to something other than the default ~/.bash_history
?
Are you the owner of .bash_history or root? Do ls -l .bash_history – Adnan Bhatti – 2013-03-29T23:23:53.580
1@MSStp yes, it is owned by me. Thanks for the suggestion but I don't see how it could be a permissions issue anyway, either I have read/write access to it or I don't. Since some history is saved, I clearly do. If bash had a setting that caused problems when this file is not owned by the user, it would either complain or the entire history functionality would not work. – terdon – 2013-03-30T00:36:04.767
when you execute
history
command, the output you see is identical to what you see, runningcat .bash_history
, other than the the line numbers ? I mean does thehistory
command list time stamps or other information ? The reason I am asking is, if you see these esoteric stuff, it means, there is another module/function/program, which is messing with the shell history and a wrong or buggy version of whatever it is, might be causing you the grief. – MelBurslan – 2013-03-30T07:54:54.953@Mel_Burslan yes it's the same, the only difference is the line numbers. – terdon – 2013-03-30T14:17:07.977
2Ok, a somewhat weird suggestion, but it's a weired problem, too
;)
: Try another file as HISTFILE, not the default~/.bash_history
. Very constructed explanation: I assume bash is your default shell, so upon system start a non-interactive shell is the parent of your X session (I also assume you use X), which will know nothing about histappend option (as .bashrc is only read by interactive shells), so as long this parent shell runs everything is fine, but upon termination (i.e. system halt) it will override~/.bash_history
(which is default) and messes up your history... – mpy – 2013-04-02T13:05:41.673hmmm, interesting @mpy, I'll give it a try. – terdon – 2013-04-02T13:12:47.073
Also, I'd suggest checking your history file, then exiting a shell, and checking the file to see if there's any immediate effect. Also, anything in
~/.bash_logout
– depquid – 2013-04-02T21:11:41.630@mpy why don't you post that as an answer, I think you have something there, see mu updated question. Changing the hist file seems to do the trick for interactive shells. Any ideas why? – terdon – 2013-04-06T13:24:34.683
@mpy do post your answer, changing the name of the default history file seems to have solved it, you should get the bounty. – terdon – 2013-04-08T15:01:01.413
@terdon: I'm glad my suggestion works. I didn't post an answer in first place, as I felt I should do some more research to give a bulletproof explanation. Not only my intuition with lots of "possible", "probably" etc. phrases. But you convinced me
;)
– mpy – 2013-04-08T16:01:33.383