Bash history not saved after closing terminal

50,383

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

Share:
50,383

Related videos on Youtube

Deepal
Author by

Deepal

NodeJS Fan and an Information Security Enthusiast

Updated on September 18, 2022

Comments

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

    Thank you

    • JBallin
      JBallin almost 6 years
      did you figure this out? if not, paste your profile/rc here for review.
  • Deepal
    Deepal almost 10 years
    histappend is 'on'. Can't figure out what's going on. :/
  • Chinmaya B
    Chinmaya B almost 10 years
    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
  • Klik
    Klik over 9 years
    Worked for me. Curious how that happened though.
  • Chris
    Chris about 9 years
    Same here. I also wonder why that happened?
  • The Guy with The Hat
    The Guy with The Hat over 6 years
    Shouldn't you set the group as well, with sudo chown yourusername:yourusername ~/.bash_history?
  • Peter
    Peter over 5 years
    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." :)
  • HCSF
    HCSF over 4 years
    histappend isn't even listed in the output of shopt -s even tho $HISTSIZE and $HISTFILESIZE are set properly. Idea? Thanks!
  • Russell Fulton
    Russell Fulton almost 4 years
    This 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
    J. Doe almost 4 years
    it happened to me once. There was blank permissions block. chmod 0644 .bash_history solved the problem "-rw-r--r--"