I used to be heavily reliant on using CtrlR to recall previously entered commands – both commonly used commands and long complicated ones. I encountered very similar issues to those you describe.
To overcome these problems, I modified my Bash configuration so that when the shell exits it appends to the history file rather than over-write it:
shopt -s histappend
However, if the shell didn’t exit cleanly (as in a hard reset), I’d still lose the history for that session so I added the following to save the history after each command is entered.
In the end, I came to embrace shell aliases as the best way to save the commonly used commands and those long complicated ones that take time to get right. As long as they’re saved to my aliases file, they’ll always be available to me – even years later.
I store all my aliases in
~/.bash_aliases and then source that file from my
.bashrc as suggested by the default
.bashrc provided by Ubuntu:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then