40

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 the history command itself. Is there any way to solve this issue?

Thank you

  • did you figure this out? if not, paste your profile/rc here for review. – JBallin Jun 18 '18 at 19:03
68

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
  • 4
    Worked for me. Curious how that happened though. – Klik Jan 8 '15 at 22:32
  • 3
    Same here. I also wonder why that happened? – Chris Apr 7 '15 at 20:49
  • 1
    Shouldn't you set the group as well, with sudo chown yourusername:yourusername ~/.bash_history? – The Guy with The Hat Nov 17 '17 at 21:35
  • Boombaa ! 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." :) – Peter Nov 12 '18 at 15:46
19

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

  • histappend is 'on'. Can't figure out what's going on. :/ – Deepal Jul 18 '14 at 8:31
  • I 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 – Chinmaya B Jul 18 '14 at 8:52
  • histappend isn't even listed in the output of shopt -s even tho $HISTSIZE and $HISTFILESIZE are set properly. Idea? Thanks! – HCSF Oct 16 '19 at 0:29

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.