brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the Up arrow can search bash history for what you already typed

Bash
~/tips/tip-bash-inputrc-history-search-arrows

"\e[A": history-search-backward

Type the start of a command, press Up, and get only matching history lines.

Up walks through every command you ever ran. With two lines in ~/.inputrc it only shows the ones that start with what is already on the line.

Add these to ~/.inputrc, the config file for Readline:

"\e[A": history-search-backward
"\e[B": history-search-forward

\e[A and \e[B are the codes most terminals send for Up and Down. Open a new terminal, type docker, press Up, and you jump straight through your earlier docker commands. On an empty line the arrows behave exactly as before.

To try it without editing a file, run bind '"\e[A": history-search-backward' in the current shell first.

I like it more than Ctrl-r for the everyday case of ‘that ssh command from yesterday’. The file is read by other programs that use Readline too, which I count as a bonus.

If the arrows still do the old thing, your terminal may send \eOA instead; find out by pressing Ctrl-v and then Up at the prompt. And when ~/.inputrc did not exist before, also add $include /etc/inputrc at the top, otherwise the system-wide settings from your distribution stop loading.

Further reading: Bash manual: Readline Init File, Bash manual: Commands For Manipulating The History

More Bash tips echo {01..10} cmd > file 2>&1 export HISTIGNORE='ls*:pwd:cd*' #rsync -av --delete /srv/media/ /mnt/backup/media/ APP_HOST=example.com All Bash tips (52) All topics

Link