To navigate Bash history for commands that start with a specific prefix using the up/down arrow keys, you can use two options :
You can always use Ctrl + R , then type part of the command — it will show the most recent matching one.
AFter hitting Ctrl + R, you'll get a new prompt (reverse-i-search): that will filter command history :
(reverse-i-search)`':
To enable prefix-based navigation (like typing git then pressing ↑ to only see commands that started with git), you need to use a feature called reverse-search history with a prefix.
~/.inputrc# Enable up/down arrow to search bash history by prefix
"\e[A": history-search-backward
"\e[B": history-search-forward
Then either:
bind -f ~/.inputrc # Apply immediately
Or restart your terminal.
sudo).↑ → It will show the last command that starts with sudo.↑ again → See earlier matching commands.