On Sun, 19 Mar 2023, Grisha Levit wrote:
When HISTTIMEFORMAT is set and history file truncation is performed,
the first line of the history file (i.e. the timestamp of the first
entry) seems to always be missing
/tmp/hist
HISTTIMEFORMAT= HISTFILESIZE=3 HISTFILE=/tmp/hist bash --norc -in <<<$'1\n2\n3'
$ cat /tmp/hist
1
#1679274410
2
#1679274410
3
For whatever it's worth, I'd noticed history truncation to roughly
HISTSIZE/2 not long after first enabling HISTTIMEFORMAT, and have used
this mnemonic since:
HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S '
HISTSIZE=$(( 10000 * 2 ))
HISTFILESIZE=$HISTSIZE
Losing the first timestamp line was a frequent occurrence with unintended
truncation due to a long-standing Fedora default [1], and my guess as to
why was something like:
- load history without HISTTIMEFORMAT set
- append a single command line, with no timestamp
- write last (default) 500 lines of "history" back to disk
Though I never tried to confirm this, being primarily concerned with the
data loss. Also never tried with an odd number for HISTSIZE.
-Rob
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1871744