Here's my setup that keeps my *nix history forever ...

=== Setup ===

First, there's the code to put in your startup scripts. For tcsh --


   # my history stuff.  Requires tcsh 6.03.  Also requires:
   #  - that the directory ~/.History exists
   #  - an occasional use of the script 'make-history'
   set history = 3000
   set savehist = 1000
   set histfile=( ~/.History/`hostname`-history-$$ )
   set histlit
   history -L ~/.history-recent

And for bash/sh/ksh/zsh --

   HISTFILESIZE=1000
   HISTSIZE=3000
   HISTFILE=~/.History/`hostname`-history-bash-$$
   history -r ~/.history-recent

(I generally use tcsh for my interactive shells, so the *sh version hasn't been nearly as well tested.)

In any event, put these entries into your ~/.tcshrc or ~/.bashrc or whatever is appropriate, and create the ~/.History directory. If you run in an environment where each system has it's own home directory, but there's a shared directory somewhere, feel free to change these (and the script mentioned shortly) put your saved history files there -- then every system will have the shell history saved from every system.

Once that's done, download the make-history script and put it somewhere in your path, and run it occasionally. Personally, I run it via cron --


0 3 * * *                $HOME/bin-generic/make-history > $HOME/.make.history.out 2>&1

and that's pretty much how it's set up. I also occasionally run it manually if I want newly started shells to have updated history lists.

=== How it's used ===

Any interactive shells that are started will have their history kept, forever, and when make-history is called, the temporary files in ~/.History will be read and put into ~/.history-master (all history entries) and ~/.history (the most recent 1995 entries, but feel free to change that in the make-history script.) The temporary files in ~/.History will be removed as they're added into the master list.

The master list only keeps one copy of each unique command -- if you run a command several times (and you almost certainly do!) it will only keep the most recent ones -- so the commonly used commands will tend to stay near the end of the list (and therefore will be added into the recent file that all shells will load) and the less commonly used (or only once used) commands will bubble towards the back of the list.

In your shells, feel free to use whatever commands you like to search through your old history. If the last 1995 lines of history isn't sufficient, this script called hs will scan the master history file for commands.

It's helpful if you occasionally exit shells where you're doing lots of work so the history can be saved to disk and processed, as opposed to leaving a single shell going for weeks. If you keep a given shell going long enough, history may be lost. If that's a problem, you could always tell your shell to save more history lines ...

I make no claims that all of this is bug-free or useful or anything like that. Basically I wrote it years ago and once I was happy with it I stopped messing with it. But feel free to send any comments, suggestions or improvements to dougmcNO@SPAMfrenzied.us (you know what to do.)

If you need a license, consider it all to be under the BSD license without the advertising clause.