Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have bash set up to save history, to a file. It does this whenever bash exits [properly]. As sometimes bash does not exit properly the history is lost.

So the question is can I set up bash to save history more regularly?

I am running Debian Gnu (version 6, Squeeze) with a Linux kernel.

bash version: GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

share|improve this question
up vote 4 down vote accepted

save this to your bash_profile or bashrc

shopt -s histappend


share|improve this answer

It's possible your $HISTFILE is owned by root. Assuming your are using bash as your login shell. Here's how to check:

$ [ -z $HISTFILE ] && echo need to set HISTFILE || ls -l $HISTFILE
-rw------- 1 root root 36639 May 21 19:48 /home/joeb/.bash_history

The default for HISTFILE should be ~/.bash_history, if you see the error "need to set HISTFILE" or if $HISTFILE is not ~/.bash_history, then you should check ~/.profile or ~/.bash_profile or ~/.bashrc to make sure it's not getting set or reset incorrectly.

Normally, it's just owned by root, so just reset it:

$ chown joeb.joeb $HISTFILE
-rw------- 1 joeb joeb 36639 May 21 19:48 /home/joeb/.bash_history

Logout then login.

$ history

Should show the last set of commands entered before the file was owned by root, followed by the commands entered after the file ownership was changed.

share|improve this answer
Since OP says that the history is saved when bash exits normally, his issue has nothing to do with the permissions. Perhaps your answer could still be useful for someone who has troubles with bash history. – Dmitry Grigoryev May 22 '15 at 13:23

You must log in to answer this question.

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