D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] lost shell history

 

Martijn Grooten wrote:
> 
> Did you have more than one shell window open? I have never figured out
> how/which history is saved when you have two (or seventeen) shell
> windows open at once and while I don't think this is the cause of the
> problem, it might have something to do with it.

man bash, and a quick play suggests the manual page is right.

By default:

set | grep HIST
HISTFILE=/home/srw/.bash_history
HISTFILESIZE=500
HISTSIZE=500

When an interactive shell exists it writes its history to the BASH
history file with the last 500 commands in its history. The file is read
on shell start up. So the contents of histfile depends which shell exits
last. Always seemed a bit naff to me, I'm thinking it can't be that hard
to use something that combines the histories of each shell sensibly.

The obvious approach would be to attach a timestamp for when a command
was last used in the history file, and on exit combine the current
"histfile" with the shells current history and write the most recent 500
back to disk rather than just the shells own. I think that way it
wouldn't matter in what order the shells exit, you'll always get the
most recent 500 commands (with the exception of command executed at the
same time, which might be ordered differently depending on what
tie-break rule one used - alphabetical by command would seem reasonable
and result in predictable output whichever order interactive shells
exist in).

However there is no obvious way this reduced to 3 entries in normal
usage unless the history was truncated, removed, or the defaults changed
somehow, so doesn't help the OP.

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html