Tuesday, August 19, 2008

Preserving History

If you use more than one terminal during your workday, you've probably been annoyed that your shell history always seems incomplete. This is due to most shells overwriting existing history data in lieu of their own history when a session is closed. Fortunately, both bash and zsh support variables to avoid this behavior.

For bash, you should be able to just add the following to your bashrc:

shopt -s histappend
PROMPT_COMMAND='history -a'

For zsh, I use the following history related options:

setopt appendhistory histignoredups
setopt histignorespace extended_history
setopt inc_append_history share_history

2 comments:

Sahir said...

In tcsh, you can have your shell merge its history into the .history file on logout by setting the following in your .cshrc:

set history = 2000
set savehist = (2000 merge)

mahasiswa teladan said...

hi..Im college student, thanks for sharing :)