0

I just want the .bash_history file to store a lot of history, like $HISTSIZE=10000000, $HISTFILESIZE=10000000 which I have set months ago.

It does not work. I just tried ^R <some old command>, no way: my history file is now at 100324 bytes.

I have a single history for all sessions. I guess it is related to the problem: some race conditions, whatever. So I tried multiple recipes for a common bash history. Now I have this one:

HISTSIZE=10000000
HISTFILESIZE=$HISTSIZE
HISTCONTROL=ignorespace:ignoredups

history() {
  _bash_history_sync
  builtin history "$@"
}

_bash_history_sync() {
  builtin history -a         #1
  HISTFILESIZE=$HISTSIZE     #2
  builtin history -c         #3
  builtin history -r         #4
}

PROMPT_COMMAND=_bash_history_sync

Do not ask me what it means. It is just another copy&paste in a hope that the history file won't repeatedly lose contents despite the large limits.

Question: how to have both common history across sessions and $HISTSIZE, $HISTOFILESIZE be the only ultimate limits of history size, nothing else trying to help them?

7
  • I'm afraid you'll always find it contains the history of the last session closed, being overwritten when the next one closes. I may be mistaken. Commented Mar 27, 2020 at 11:38
  • I can see stuff in my bash history that I did 16 days back, and I power down every night and cold-boot every morning. Maybe try a cron or shutdown job that rolls off the history to dated files that you can search. Commented Mar 27, 2020 at 12:22
  • @Gerard what is then the use of shopt -s histappend and builtin history -a? Commented Mar 27, 2020 at 13:14
  • Sorry, I only use ksh. Commented Mar 27, 2020 at 13:28
  • see this answer to another question: unix.stackexchange.com/a/428208/4721 Commented Mar 27, 2020 at 13:34

0

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.