I'm new on Unix&Linux and wanted to comment on an already exhaustive approach to a different question. My rep isn't 50, yet (sad), so it won't let me. I tried this solution to this question: Preserve bash history in multiple terminal windows

export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
export HISTSIZE=100000                   # big big history
export HISTFILESIZE=100000               # big big history
shopt -s histappend                      # append to history, don't overwrite it

# Save and reload the history after each command finishes
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Unfortunately, this causes the result that while I have a growing (merged) history (desired), in new windows, I can no longer cycle through any of it using the 'up-arrow' (undesired). That is, I can only cycle through commands executed within the new window. Eg, if I open a new terminal and have 500 lines of history incoming, I execute 3 commands, I can only cycle through those 501-503 with the up-arrow...

I open a new terminal and do the following:

$ history #enter
  584 foo
  585 bar
  600 baz

$ history #enter

  1 history

Could somebody explain why this is so, and if there is a workaround? Thanks.

  • do you have unique $HISTFILEs?
    – Jeff Schaller
    Jul 10, 2017 at 17:01
  • Yes, I do. It's the line that alters PROMPT_COMMAND that is the culprit. I've since turned it off and normal behavior has returned, but I'd at least like to understand what was going on. Jul 10, 2017 at 17:04
  • Seems to me that unique history files would get in the way of separate shells reading separate histories.
    – Jeff Schaller
    Jul 10, 2017 at 17:08

2 Answers 2


Seems the solution can be navigated to from comment section in the link I posted: see Bash history: "ignoredups" and "erasedups" setting conflict with common history across sessions

Rather than:

export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"


PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"

The reason to have the history of all places where bash has an history (and writes to it) is that you are writing to the file (history -a) and all other bash shells are also writing to the same file.

Then, you are reading all commands from the file (history -r) to memory.

As a solution, you can write (new) commands to the file (history -a), but not read the resulting file. The list of commands in memory will belong to each instance of bash running. Each instance of bash will have a diferent list of commands. All commands will be written to the history file.

Use (in bashrc or similar):


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .