Bash history not saved after closing terminal
Solution 1
It may be that your .bash_history doesn't belong to your user. Check the permissions of the file and if you're not the owner, change it:
sudo chown yourusername:yourusername ~/.bash_history
Solution 2
First type following command
shopt -s
to check weather histappend
command is 'on' or 'off'
If it is off then type following command to append history
history -a
If you want to save history with every new prompt run following command
export PROMPT_COMMAND='history -a'
For more information see this link
Related videos on Youtube
Comments
-
Deepal over 1 year
I recently replaced my Ubuntu 14.04 installation with Ubuntu Gnome (which comes with Gnome DE). But I noticed that bash history is not saved once the terminal session is closed. Once I close a terminal session and open a new one, and run the command
history
it does not show anything other than thehistory
command itself. Is there any way to solve this issue?Thank you
-
JBallin almost 6 yearsdid you figure this out? if not, paste your profile/rc here for review.
-
-
Deepal almost 10 years
histappend
is 'on'. Can't figure out what's going on. :/ -
Chinmaya B almost 10 yearsI think some pipe connecting to history file is broken ,because if from terminal history is append then only it can be case of broke pipe try reparing or reinstalling system if you can
-
Klik over 9 yearsWorked for me. Curious how that happened though.
-
Chris about 9 yearsSame here. I also wonder why that happened?
-
The Guy with The Hat over 6 yearsShouldn't you set the group as well, with
sudo chown yourusername:yourusername ~/.bash_history
? -
Peter over 5 yearsBoombaa ! I take this moral from the story: "When such basic facility fails (and by default is ON), then most likely this is due to famous "permissions: problem." :)
-
HCSF over 4 years
histappend
isn't even listed in the output ofshopt -s
even tho$HISTSIZE
and$HISTFILESIZE
are set properly. Idea? Thanks! -
Russell Fulton almost 4 yearsThis fixed the problem for me too. I strongly suspect that sudo -s was the problem but it does not happen every time. I note that -s leaves the home dir as the original. I was using that before my history vanished.
-
J. Doe almost 4 yearsit happened to me once. There was blank permissions block.
chmod 0644 .bash_history
solved the problem "-rw-r--r--"