Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am working on a x86 target running fedora 9.

Whenever I reboot it, my history returns to some state, and I do not have commands I did in the sessions before the reboot.

What I have to change to have updated history I had before reboot?

share|improve this question

migrated from stackoverflow.com Nov 17 '10 at 17:43

This question came from our site for professional and enthusiast programmers.

He is asking "How do I keep my bash history across sessions?", which is related to shell programming. The reboot is a dramatic way of losing your shell, that's all. It doesn't need closing off topic. –  Jonathan Leffler Nov 17 '10 at 15:00
Good point—this probably should be moved to SuperUser. –  B.R. Nov 17 '10 at 15:02
@Jonathan Yes, you got the question correct. I wasn't sure what exactly to ask. –  VJo Nov 17 '10 at 16:02
Saving each command right after it has been executed, not at the end of the session will also help. This is because if you are running two sessions simultaneously, then without the line below, bash will save the history from session-1 (say) when its closed. If session-1 is running and you want to immediately access the history of session-1 inside session-2, then you wont be able to unless you add the below line to the .bashrc file. PROMPT_COMMAND='history -a' –  Abhinav Aug 4 '13 at 22:05

5 Answers 5

up vote 9 down vote accepted

Which history? bash-history? If you're losing bash history and you have multiple sessions at a time, it's because each session is overwriting the other sessions' history.

You probably want to tell bash to not overwrite the history each time, but rather to append to it. You can do this by modifying your .bashrc to run shopt -s histappend.

You can also increase the size of your history file by exporting HISTSIZE to be a large-ish number (it's in bytes, so 100000 should be plenty).

share|improve this answer
HISTSIZE is the number of commands to remember, not the number of bytes. –  Chris Down Jun 12 '14 at 3:04

Look up the environment variables HISTFILE, HISTSIZE, HISTFILESIZE.

share|improve this answer

I was suffering from the same problem - but my .bashrc file already had the shopt -s histappend and correct HISTFILE, HISTSIZE, HISTFILESIZE.

For me the problem was that my .bash_history file was owned by root rather than my username, so my user could never save to that file on exit.

share|improve this answer
I just found I had exactly the same problem with .bash_history owned by root. I wish I'd realized before I'd lost all my lovely history, but nevermind :-) –  SamStephens Jul 16 '13 at 16:47

I have written a script for setting a history file per session or task its based off the following.

    # write existing history to the old file
    history -a

    # set new historyfile
    export HISTFILE="$1"
    export HISET=$1

    # touch the new file to make sure it exists
    touch $HISTFILE
    # load new history file
    history -r $HISTFILE

It doesn't necessary save every history command but it saves the ones that i care about and its easier to retrieve them then going through every command. My version also lists all history files and provides the ability to search through them all.

Full source: https://github.com/simotek/scripts-config/blob/master/hiset.sh

share|improve this answer

Good answer to this question is here:


share|improve this answer
Welcome to SuperUser! Please include enough information in your answer that the asker doesn't have to click on an external link. Also, make sure your answer doesn't simply duplicate existing answers (which, from a quick glance at that link, it seems to be doing). –  Indrek May 16 '12 at 0:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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