4

I'm using this in my .bashrc since 2 years now, and never noticed any problem...until recently.

I noticed that the .bash_eternal_history, which was more than 40k lines, suddenly gets truncated on new login, down to a couple hundreds lines.

I tried checking HISTSIZE and HISTFILESIZE but it was still returning nothing (which I assume mean it doesn't have any limits)

I'm aware of this other post that mentions that unsetting those variables is preferred, but in this other one, it doesn't seem to always be the case.

I found an alternative (didn't tried it yet) such as this one.

I'm using Ubuntu's default .bashrc, with HISTSIZE and HISTFILESIZE commented, since already part of the defaults (so that it doesn't interfere with the snippet mentioned above).

Other related posts I consulted:

I didn't yet tried the alternative I mentioned above, and so I'm curious if there could be other reasons for this to happen, outside what I found in the mentioned posts.

2
  • 1
    See my answer over on AskUbuntu askubuntu.com/questions/80371/…
    – waltinator
    Commented Oct 27, 2023 at 0:23
  • I did something similar, albeit a bit more complicated. On shell exit, I run a script to save the history to a file with the current date. The way you did it is better since it does it at shell start, not exit. @waltinator Appreciate this. Commented Oct 27, 2023 at 4:51

1 Answer 1

3

From man bash:

   HISTFILESIZE
          The maximum number of lines  contained  in  the  history  file.
          When  this  variable  is  assigned a value, the history file is
          truncated, if necessary, to contain no more than that number of
          lines by removing the oldest entries.  The history file is also
          truncated to this size after writing it when a shell exits.  If
          the  value  is  0,  the history file is truncated to zero size.
          Non-numeric values and numeric values less  than  zero  inhibit
          truncation.   The  shell sets the default value to the value of
          HISTSIZE after reading any startup files.
   HISTSIZE
          The  number of commands to remember in the command history (see
          HISTORY below).  If the value is 0, commands are not  saved  in
          the  history list.  Numeric values less than zero result in ev‐
          ery command being saved  on  the  history  list  (there  is  no
          limit).   The shell sets the default value to 500 after reading
          any startup files.

So if neither are set, the code will still default to 500 for both.

2
  • but as i mentioned, i did check the value of those two value, and they weren't set at any value (didn't return anything when i checked with echo) Commented Sep 24, 2020 at 16:30
  • 1
    I think "sets the default value" is misleading, and just means the internal state of the shell is that the history sizes are 500. The variables are just a copy of that state so that it's (normally) easily interrogated by the end user.
    – l0b0
    Commented Sep 24, 2020 at 20:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .