Bash – Keep two bash history files, one with ignoredups, one with everything

bashbashrccommand history

For the purposes of looking at which commands I am using the most, I'd like to keep a record of command I type in my bash history (even duplicates).

But, for sanity and ease of use, I still want to keep my ignoredups setting on.

Is there a way to automatically create two history files? With the "default" being no duplicates, and the full history elsewhere?

Best Answer

You could ignore the builtin history mechanism and abuse $PROMPT_COMMAND to write history any way you wanted. Some people keep a directory of history files, one for each shell/date/hostname, etc. Approximately something like this:

prompt_cmd() {
    echo "$_" >> $HOME/.my_history_file_$HOSTNAME
}

PROMPT_COMMAND=prompt_cmd

obviously embellish with dates, times, whatever...