Skip to content
Go back

Preserving Bash History in Multiple Terminal Windows

By SumGuy 3 min read
Preserving Bash History in Multiple Terminal Windows

When working with Linux, particularly in environments where multiple terminal windows are common, such as in programming or system administration, it’s crucial to have access to your command history across all sessions. By default, the Bash shell does not immediately share history between its instances. This can be inconvenient when you need to recall commands executed in another terminal window. However, there are ways to configure Bash to share its history more effectively.

How to Configure Shared Bash History

To make your Bash history immediately accessible across multiple terminal windows, you need to modify how Bash handles its history file (~/.bash_history). Here’s a step-by-step guide to achieve this:

nano ~/.bashrc
# Avoid duplicates
HISTCONTROL=ignoredups:erasedups
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend
# After each command, append to the history file and reread it
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Here’s what each line does:

source ~/.bashrc

Pros and Cons of Sharing Bash History

Pros:

Cons:

Tips for Managing Bash History

export HISTSIZE=10000
export HISTFILESIZE=20000

Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Previous Post
Ansible: Task and Role Inclusions for Efficient Automation
Next Post
Finding the PID of a Process Using a Specific Port in Linux

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts