Skip to main content
Add info for how to immediately bind the new keybindings
Source Link

First of all, hitting tab in bash is even better since it autocompletes all executables in your PATH irrespecitve of whether they're in the history. That said, there are various ways of getting a command from your history:

  1. Use its number. If you know that the command you want was 3 commands ago, you can just run

     !-3
    

That will re-execute the command you ran three commands ago.

  1. Search for it. Type Ctrlr and start typing any text. The first command from the history that matches your text will be shown and hitting enter will execute it.

  2. Hit (up arrow). That will bring up the last command, press it again and you will go up your command history. When you find the one you want, hit enter.

  3. Add these lines to your ~/.inputrc (create the file if it doesn't exist):

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

To immediately load the file, run bind -f ~/.inputrc (source). Now, type the first few characters of one of the commands you've previously run and hit . The first command from your history that starts with those characters will be shown. Hit again to see the rest and hit enter when you've found the one you want.

  1. Use the history command. As @Isaac explained, that will list all of the commands stored in your history file.

First of all, hitting tab in bash is even better since it autocompletes all executables in your PATH irrespecitve of whether they're in the history. That said, there are various ways of getting a command from your history:

  1. Use its number. If you know that the command you want was 3 commands ago, you can just run

     !-3
    

That will re-execute the command you ran three commands ago.

  1. Search for it. Type Ctrlr and start typing any text. The first command from the history that matches your text will be shown and hitting enter will execute it.

  2. Hit (up arrow). That will bring up the last command, press it again and you will go up your command history. When you find the one you want, hit enter.

  3. Add these lines to your ~/.inputrc (create the file if it doesn't exist):

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

Now, type the first few characters of one of the commands you've previously run and hit . The first command from your history that starts with those characters will be shown. Hit again to see the rest and hit enter when you've found the one you want.

  1. Use the history command. As @Isaac explained, that will list all of the commands stored in your history file.

First of all, hitting tab in bash is even better since it autocompletes all executables in your PATH irrespecitve of whether they're in the history. That said, there are various ways of getting a command from your history:

  1. Use its number. If you know that the command you want was 3 commands ago, you can just run

     !-3
    

That will re-execute the command you ran three commands ago.

  1. Search for it. Type Ctrlr and start typing any text. The first command from the history that matches your text will be shown and hitting enter will execute it.

  2. Hit (up arrow). That will bring up the last command, press it again and you will go up your command history. When you find the one you want, hit enter.

  3. Add these lines to your ~/.inputrc (create the file if it doesn't exist):

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

To immediately load the file, run bind -f ~/.inputrc (source). Now, type the first few characters of one of the commands you've previously run and hit . The first command from your history that starts with those characters will be shown. Hit again to see the rest and hit enter when you've found the one you want.

  1. Use the history command. As @Isaac explained, that will list all of the commands stored in your history file.
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

First of all, hitting tab in bash is even better since it autocompletes all executables in your PATH irrespecitve of whether they're in the history. That said, there are various ways of getting a command from your history:

  1. Use its number. If you know that the command you want was 3 commands ago, you can just run

     !-3
    

That will re-execute the command you ran three commands ago.

  1. Search for it. Type Ctrlr and start typing any text. The first command from the history that matches your text will be shown and hitting enter will execute it.

  2. Hit (up arrow). That will bring up the last command, press it again and you will go up your command history. When you find the one you want, hit enter.

  3. Add these lines to your ~/.inputrc (create the file if it doesn't exist):

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

Now, type the first few characters of one of the commands you've previously run and hit . The first command from your history that starts with those characters will be shown. Hit again to see the rest and hit enter when you've found the one you want.

  1. Use the history command. As @Isaac explained, that will list all of the commands stored in your history file.