13

I am using ubuntu 13.04, in this the command history of the shell is getting erased on close.

Can someone tell me how to prevent this from happening?

2
  • 2
    i have solved the issue. the user i am logged into doesnot have the read/write permissions for .bash_history file so i changed the permissions and it worked. – Aditya Shanker Tagirisa Aug 3 '13 at 8:40
  • @Kartik i cannot answer my own question until 8 hours from the time i created the question that's why i added it in the comment – Aditya Shanker Tagirisa Aug 3 '13 at 10:55
18

At a Bash prompt, type the following commands and do the steps listed after each one:

set -o | grep history

If you get "history off" then add this line at the end of your ~/.bashrc:

set -o history

Next try:

echo $HISTFILE
echo $HISTSIZE
echo $HISTFILESIZE

If the first one is blank or /dev/null, add this line to the end of your ~/.bashrc:

HISTFILE=$HOME/.bash_history

If either of the last two print 0, set them to some number like the default of 500:

HISTFILESIZE=500
HISTSIZE=500

Do not forget to source .bashrc after saving ~/.bashrc

1
  • execute source .bashrc after saving ~/.bashrc – user427969 Aug 2 '19 at 2:59
1

Another possible problem I just encountered is that your .bash_history file might be owned by root:

$ ls -l $HISTFILE
-rw------- 1 root root 9558 Jun 21 21:56 /home/ubuntu/.bash_history

The solution is to chown it back to your user and group:

$ sudo chown ubuntu:ubuntu /home/ubuntu/.bash_history
$ ls -l $HISTFILE
-rw------- 1 ubuntu ubuntu 9558 Jun 21 21:56 /home/ubuntu/.bash_history

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.