Is there a key combination for bash to auto compete a command from the history? In ipython and matlab for example this is achieved by pressing up arrow after typing a few characters.
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:
Use its number. If you know that the command you want was 3 commands ago, you can just run
That will re-execute the command you ran three commands ago.
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.
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.
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.
- Use the
historycommand. As @Isaac explained, that will list all of the commands stored in your history file.
You can also use
history and pipe the output for a specific command.
For example, if you've been
cd-ing all around the file system all day and just need a reminder of what directories were worked on
history | grep cd
You could then either copy/paste the command, or
!n (where n is the line number in history file) to re-execute it.