Find the answer to your Linux question:
Results 1 to 4 of 4
I've noticed that when I have many sessions open, the history from one closed session will overwrite the history from another earlier closed session so that when I open a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie humbletech99's Avatar
    Join Date
    Nov 2005
    Posts
    225

    Retaining Bash history from all sessions


    I've noticed that when I have many sessions open, the history from one closed session will overwrite the history from another earlier closed session so that when I open a new session I only see the history of the most recently closed session.

    Is there a way I can merge/retain all Bash history from all sessions?

    I was thinking about something in the .bash_logout, perhaps a func to merge the histories, appending only the new lines to the history file, but the problem is that the history numbering overlaps, so this could be tricky.

    Another question would be how Bash handles the history, is it before or after the processing of the history file? If it's after, then would bash just overwrite the history file with the current session history regardless of what is in .bash_logout?

    Any Ideas?
    The Human Equation:

    value(geeks) > value(mundanes)

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Insert the 2 statements into ~/.bashrc:

    Code:
    shopt -s histappend
    PROMPT_COMMAND="$PROMPT_COMMAND;history -a"
    The first command appends the commands to the history file, rather than overwrite it while the second command saves each command right after it has been executed, not at the end of the session.

    Regards

  3. #3
    Linux Newbie humbletech99's Avatar
    Join Date
    Nov 2005
    Posts
    225
    ah this actually works nicely. thanks.
    The Human Equation:

    value(geeks) > value(mundanes)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Newbie
    Join Date
    Dec 2004
    Location
    Portland, OR
    Posts
    123
    Franklin52 - this is great! Thanks for posting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •