capturing bash history

Bob Walker bob at
Tue Jun 12 13:27:01 BST 2007

On Tue, 12 Jun 2007, Aaron Crane wrote:

:> Nigel Hamilton writes:
>> I'd like to keep a history of all shell commands across all the xterms I'm
>> using but the ~/.bash_history only holds history from one terminal.  Any
>> ideas on interleaving the shell history from multiple terminals into one
>> file?
> This is the magic:
>  # Append to the history file on shell exit, don't overwrite (so multiple
>  # exiting shells don't race to scribble over your saved history)
>  shopt -s histappend
>  # Keep lots of history around
>  export HISTSIZE=1000000 HISTFILESIZE=1000000
>  # Store history in a different file, so it won't get overwritten if you
>  # don't have these settings
>  export HISTFILE=~/.bash_history_safe
>  # Write unsaved history immediately before emitting each prompt
>  export PROMPT_COMMAND='history -a'
> I stole most of that from Smylers:
>> p.s. it would be great if I could get this to work across multiple machines
>> too --- but I'll settle for one machine to start with
> I've never wanted that, but it's essentially going to be a matter of copying
> history files from place to place, and appending their deduped contents to
> the desired history file on each machine.  I suspect the trickiest bit is
> working out when to do it; on each prompt sounds painfully slow, for example.

Bob Walker
For great beery Justice!

More information about the mailing list