🧠 SynapseNotes

Search

Search IconIcon to open search

Preserve Bash History from Multiple Terminal Windows (Linux)

Last updated Jul 24, 2023

“In this tutorial, we studied ways to preserve Bash history in multiple terminal windows on Linux .

In the beginning, we discussed the history feature of the Bash shell and its default behavior. Next, we discussed the approach and solutions to our problem statement. Finally, we also offered a way to create a separate history file for each session.”

# Commands:

Access the .bashrc configuration file

1
sudo nano ~/.bashrc

Then inside that file we add:

1
2
3
HISTCONTROL=ignoredups:erasedups
shopt -s histappend
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'n'}history -a; history -c; history -r"

# Reboot or Reload Terminal Config.

We save the file and then we restart the system or do source ~/.bashrc to load configurations.

# Source

Source: https://www.baeldung.com/linux/preserve-history-multiple-windows