23

I generally find myself using two or three tabs in my Terminal on OS X.

A minor inconvenience is that, by default, the tabs don't share their command history. So, searching for a previous command that I ran on another tab by typing history | grep thingIamlooking for does not find it.

Is there a way of forcing Terminal tabs to share history, or is there some other "history_of_all_tabs" command?

29

I don't think there is a way to share history amongst Terminal tabs only, but here is something that could help you.

The history is not something that is handled by your terminal but by your shell (bash, tcsh, zsh, etc.)

Here are some options that'll help you set up a shared history amongst all the terminal windows (the shell instances).

This should be put somewhere in your .bashrc file.

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"
  • 1
    +.5 for good answer, +.5 for good grammar ;) – Matt Jul 26 '12 at 9:49
  • @Lifely's solution isn't working for me in El Capitan. At all. Even the max length of the history file. Is there a new solution since 2012? (I'd have commented above, but don't have the rep) – JP Duffy Apr 26 '16 at 20:17
  • 1
    This is working for me (added in .bash_profile) in El Capitan with the addition of export SHELL_SESSION_HISTORY=0 in my .bash_profile and running: touch ~/.bash_sessions_disable – Andy May 31 '16 at 17:12
  • works great on Ubuntu 18.04 for bash – anon58192932 Sep 26 '18 at 0:45

You must log in to answer this question.

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