M BUZZ CRAZE NEWS
// general

reverse-i-search of history not finding expected commands

By Daniel Rodriguez

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.

2

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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