reverse-i-search of history not finding expected commands
Today upon bringing up a bash terminal I tried finding a frequently-used command from my bash history via Ctrl-r. To my surprise, it wasn't found. Upon inspecting ~/.bash_history, I saw instances of the command on several lines. Does the command history not work by checking the file, either in real time or against a cached copy?
2 Answers
It turns out there was a little more nuance than I was aware of: HISTFILESIZE determines the maximum number of lines saved in .bash_history, while HISTSIZE determines the number of lines from ~/.bash_history loaded into a searchable cache. Upon increasing HISTSIZE to match HISTFILESIZE, I was able to find the command via Ctrl-r.
Apart from this (HISTFILESIZE), there is one reason why a line won't appear in history: A leading space. If you start a command with a space in the front like this:
$ ls -l
$ ls -l (extra space at the beginning)
then the latter won't show up in history. Related, here is what my .bashrc looks like:
.bashrc:HISTCONTROL=ignoreboth
.bashrc:export HISTSIZE=100000
.bashrc:export HISTFILESIZE=100000
.bashrc:export HISTCONTROL=ignoredups:erasedups
.bashrc:export HISTTIMEFORMAT="%d/%m/%y %T "HTH
More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"