bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Suggestion] Flush command history to a "backup" file periodically


From: Greg Wooledge
Subject: Re: [Suggestion] Flush command history to a "backup" file periodically
Date: Thu, 19 Jan 2023 20:53:12 -0500

On Fri, Jan 20, 2023 at 12:08:36AM +0000, Peter wrote:
> Currently, in the event bash or something below it crashes, that
> session's command history is lost.
> It would be nice if bash saved it somewhere periodically, it doesn't
> have to be too often, let's say on every second command.

History management is an extremely serious personal mission for some
people.  For others, not so much.

The good news is, bash gives you plenty of tools to create your own
personalized history management system.  For you, perhaps something
like this might work:

 * In .bashrc, set seconds_since_history_save=0

 * Set up PROMPT_COMMAND to check whether the difference between
   SECONDS and seconds_since_history_save is greater than some threshold
   value.  If it is, write history to a file, and set
   seconds_since_history_save=$SECONDS.

Details left to the reader.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]