2

I just noticed that a lot of entries are missing from my bash command history (the .bash_history file).

I'd like to know:

  • if there is a way to find out why commands are missing from the file (like a lack of disk space; I could not find hints in /var/log/syslog)
  • if there are ways, issues or ongoing work to make sure that the bash history always reliably includes all executed bash commands - for example by copying a backup of the latest .bash_history file before overwriting it, doing so after every executed command and having a filesize-buffer in case disk space gets too low

The .bashrc file already has HISTSIZE and HISTFILESIZE set to very large values. I have backups of the .bash_history file.

5
  • 1
    What says shopt histappend? If is not set the last shell to close overwrites whatever other shells have added.
    – xenoid
    Commented Apr 25, 2020 at 11:04
  • It says histappend on. If that isn't the default setting that would be yet another problem.
    – mYnDstrEAm
    Commented Apr 25, 2020 at 11:39
  • If you diff the backups, do they only differ at the end or also at the beginning and/or middle of the files? Also what are te outputs of sudo grep -r '^HIST' /etc/* and grep '^HIST' ~/\.*?
    – bey0nd
    Commented Apr 26, 2020 at 8:12
  • It sadly looks like there's no overlap: the earliest commands of the current .bash_history file aren't in any of my backup files. I made the last backup of it a not-too-long while before the first command of the current one. It's mostly commands a short while after upgrading to Debian 10 that are missing now. Outputs: /etc/skel/.bashrc:HISTCONTROL=ignoreboth /etc/skel/.bashrc:HISTSIZE=1000 /etc/skel/.bashrc:HISTFILESIZE=2000 /etc/sysstat/sysstat:HISTORY=7 & /home/username/.bashrc:HISTCONTROL=ignoreboth /home/username/.bashrc:HISTSIZE=100000 /home/username/.bashrc:HISTFILESIZE=200000
    – mYnDstrEAm
    Commented Apr 26, 2020 at 9:10
  • The issue doesn't seem to be caused by lack of disk space (created a bash bug report). Recently, lots of bash history entries were missing after a restart after a kernel upgrade (a Debian 11 upgrade) and it doesn't look like I was scarce on disk-space (nor did it display a warning at the time or afterwards). It wasn't a restart due to a freeze/crash either this time. Moreover, Vorta/borg backups for a few weeks are missing even though the target location has enough disk space and I configured Vorta to not prune these and I haven't deleted them. Backups were carried out again after the restart.
    – mYnDstrEAm
    Commented Dec 28, 2021 at 10:58

1 Answer 1

1

The command history of your current shell is written to .bash_history when you close the shell. Therefore, while usually all recent commands are accessible from the shell, they are not yet added to the .bash_history file.

1
  • Thank you. That's another problem. Hundreds of older commands are missing.
    – mYnDstrEAm
    Commented Apr 25, 2020 at 9:42

You must log in to answer this question.

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