Bash: History Searching with .inputrc
Today I’ll show you one of my favorite Bash history tweaks.
If you’re working - or living - inside a Bash shell then this if for you:
By simply uncommenting two lines in the default inputrc you’ll get to browse through your Bash history using the PgUp/PgDn (Arrow Up/Down) keys. Like a “Bash history auto-completion” on steroids, a nifty little feature you might come to appreciate.
For me, this little tweak has massively increased my perceived productivity, so much that I feel life would be really burdensome without it.
So here’s how you’d go about it:
Copy the system default .inputrc
Copy the default Debian inputrc to .inputrc in your home directory:
$ cp /etc/inputrc ~/.inputrc
Uncomment the history-search lines
Edit your .inputrc and uncomment so it looks like this:
Now simply open a new shell.
You’ll be able to browse through your command line history, simply start typing a few letters of the command and then use the arrow up and arrow down keys to browse through your history. This is similar to using
Ctrl+r to do a reverse-search in your Bash, but a lot more powerful, and a feature I use every day.
The .inputrc is basically the configuration file of
readline - the command line editing interface used by Bash, which is actually a GNU project library. It is used to provide text related editing features, customized keybindings etc.
Increase your Bash history longevity
Your Bash history can be really valuable. Imagine you did some Bash command line kung fu some months/years ago on a project you where really into at that time, and need to redo your work or an urgent maintenance task has come up.
So instead of trying to figure out things again - re-invent the wheel so to say - you simply go through your Bash history, find the command line you need and fire it off.
Add the following to .bashrc to ensure that you keep a loooong Bash history:
export HISTSIZE=1000000 export HISTFILESIZE=1000000000
Treat your Bash history with the respect it deserves, it can be a valuable knowledge base. You never know when you might need it, but when you do it’s good to have it.
“Those who cannot remember the past are condemned to repeat it” – George Santayana
#Bash #Debian #Linux