2

I use a common history for all sessions. It happens to me frequently, that a part of the history is lost, however. Therefore, I just swap different "common session" scripts in a hope that one will fix it, no way so far. It works mostly, but not always.

I just decided to look more closely into this, when Ctrl+R valgrind showed nothing. Yes, it is in the history file - opening .bash_history in an editor and searching shows multiple commands that begin with valgrind. Still, history |grep valgrind shows just itself, and in fact, that very command is put into the said .bash_history, at the very end of it, long after the other commands containing valgrind. And it is not a typo - the history file contains many iptables commands, these are invisible by history and by Ctrl+R. The more recent history in the same file is visible and accessing it works fine.

I would doubt, that Bash history is broken so much. Any explanation?

EDIT: There is a similar question, with no real answer: Is there a limit on how many entries the 'Control R' bash shortcut searches?

asked Feb 6, 2019 at 13:04
4
  • 1
    Does this help? superuser.com/questions/211966/… Commented Feb 6, 2019 at 13:14
  • No. As I said, I already use a common Bash history. Commented Feb 6, 2019 at 13:27
  • So you did, sorry. Commented Feb 6, 2019 at 13:30
  • Can you check your ~/.bashrc to see what is HISTSIZE and HISTFILESIZE set to? Commented Oct 24, 2019 at 21:16

1 Answer 1

0

bash does not load the whole ~/.bash_history at the start of the session. It only loads a number of commands specified by shell variable HISTSIZE.

There is a difference between the history that is kept in memory and history that is saved in ~/.bash_history file. To make bash load more from ~/.bash_history you need to set HISTSIZE to a higher number.

GNU bash documentation:

The value of the HISTSIZE shell variable is used as the number of commands 
to save in a history list.

The "history list" in the documentation refers to the history kept in memory.

answered Oct 23, 2019 at 17:48
5
  • The commands which can not be recalled are already saved in the history file. Commented Oct 24, 2019 at 20:39
  • The size of the history loaded in memory and size of the history that is kept in the HISTFILE are two different things. If your HISTFILESIZE is larger than HISTSIZE then the number of commands loaded into memory can be smaller than the total number commands in your HISTFILE. Commented Oct 24, 2019 at 21:13
  • This SO question explains that in detail: stackoverflow.com/questions/19454837/… Commented Oct 24, 2019 at 21:15
  • I extended the answer to explain the difference between the history file and the history in memory. Commented Oct 24, 2019 at 21:40
  • My .bashrc contains HISTFILESIZE=$HISTSIZE, at least now... I do not know if it was the case when I wrote this question. I will set both to 10M and see if relatively recent commands are still lost sometimes. Commented Oct 25, 2019 at 20:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.