History - Search Shortcuts

Boost your productivity in the Linux shell with quick history search commands using your arrow keys.
These shortcuts let you instantly find previously executed commands without retyping them.


Why This Matters

If you often repeat commands or tweak long terminal instructions, history search is a huge time-saver.
By enabling this feature, your Up and Down arrows can search through your history by prefix, not just by recent order.


Steps

  1. Open your bash configuration file:

    vi ~/.bashrc
    
  2. Add the following lines at the end of the file:

    bind '"\e[A":history-search-backward'
    bind '"\e[B":history-search-forward'
    set show-all-if-ambiguous on
    set completion-ignore-case on
    
  3. Save the file and refresh your current shell:

    source ~/.bashrc
    

Bonus section

  1. In Powershell it is possible too, just create this file

    vim %HOME%\Documents\WindowsPowerShell\profile.ps1
    
  2. Add the following lines to the file:

    Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
    

Related Posts