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?


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.

  • Thanks for posting this Q&A. I hope this clear demonstration of the interaction of these variables will help others too. – glenn jackman Sep 22 '20 at 15:05
  • It actually started as just a Q, but a few more minutes of digging yielded an answer! – BipedalShark Sep 22 '20 at 15:08

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:export HISTSIZE=100000
.bashrc:export HISTFILESIZE=100000
.bashrc:export HISTCONTROL=ignoredups:erasedups
.bashrc:export HISTTIMEFORMAT="%d/%m/%y %T "


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.