#741950 bash: histfilesize always 2000 lines

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
Richard Lucassen
Date:
2024-04-05 10:12:02 UTC
Severity:
normal
Tags:
#741950#5
Date:
2014-03-17 15:34:38 UTC
From:
To:
$ echo $HISTFILESIZE
50000

The value is set at the last line of ~/.bashrc:

if [ -f /etc/bash.custom ]; then
  . /etc/bash.custom
fi

$ grep HIST /etc/bash.custom
HISTFILESIZE=50000
HISTSIZE=-1
HISTCONTROL=erasedups
export PS1 HISTCONTROL HISTSIZE HISTFILESIZE PAGER PATH

$ wc -l .bash_history
2000 .bash_history

Even when HISTFILESIZE is exported to 50000, the number of lines in .bash_history is limited to the default setting of 2000 lines.

This has been working perfectly well until some time ago, I noticed that regularely used commands had disapeared from the history file and that the file is truncated to 2000 lines, whether the HISTFILESIZE is set or not.

Richard.

#741950#10
Date:
2014-03-27 00:04:08 UTC
From:
To:
the HISTFILESIZE, which was set to 2000.

Setting HISTFILESIZE to another value worked, but when an xterm was
started the .bash_history was truncated to 2000.

R.

#741950#15
Date:
2020-05-21 13:12:53 UTC
From:
To:
Hi,

I also encountered this issue that my '~/.bash_history' was always
truncated to 2000 lines despite myself having set 'HISTSIZE' and
'HISTFILESIZE' to larger values in my '~/.bash_aliases' and it took me a
while to find out what was going on.

In fact, 'HISTFILESIZE=2000' is set in '/etc/skel/.bashrc', which is
shipped by the Debian package, so the '~/.bashrc' file created from that
skeleton file contains that line for every user by default.

The corresponding changelog entry for version 4.2-1 (November 2011)
where those lines were added is the following
find the current sitation unfortunate, since it not only sets the value
for the environment variable, but immediately truncates the bash history
file, '~/.bash_history'.

Setting a value for HISTFILESIZE in the skel file therefore effectively
makes it impossible for users to simply override that value by setting
it to another value in '~/.bash_aliases' (which is sourced in
'~/.bashrc' as provided by the skeleton file), which in my understanding
is usually regarded as the recommended way to set user-specific values.

Thus, users would have to edit '~/.bashrc' in addition (and know that
this is needed, which is probably rather unexpected for most users).

The issue of truncation by setting HISTFILESIZE is easily demonstrated
by the following commands:

$ rm ~/.bash_history
$ for i in {1..2000}; do echo "echo $i" >> ~/.bash_history ; done
$ wc -l ~/.bash_history
2000 /home/michi/.bash_history
$ HISTFILESIZE=1000
$ wc -l ~/.bash_history
1000 /home/michi/.bash_history
$ HISTFILESIZE=500
$ wc -l ~/.bash_history
500 /home/michi/.bash_history

Apparently, setting HISTFILESIZE to a larger value later (which a user
might do in ~/.bash_aliases) does not bring back the deleted entries:

$ HISTFILESIZE=5000
$ wc -l ~/.bash_history
500 /home/michi/.bash_history


To avoid this and allow the user to simply set the desired history
length via environment variable in '~/.bash_aliases', I would recommend
to only set the 'HISTSIZE' variable, which is what 'HISTFILESIZE'
defaults to when not set explicitly.

From bash's man page:


By setting 'HISTSIZE' to 2000 and not setting HISTFILESIZE in the
skeleton file, the default size of the history file remains 2000 lines,
but it can easily be overriden by users.

I have attached a patch that does this and would be thankful if such a
change were considered.

Regards,
Michael