在Bash(以及大多数基于readline的应用程序)中,您可以按下Ctrl-R
以显示历史搜索功能:
$ date
Tue Feb 1 15:40:06 EET 2011
(reverse-i-search)`d': date
按Enter
此处我得到:
$ date
Tue Feb 1 15:40:06 EET 2011
$ date
Tue Feb 1 15:40:52 EET 2011
编辑:
您可以在此处查看与历史记录相关的Bash键击的完整列表。
您可以看到历史搜索键盘绑定的当前列表:
$ bind -P | grep search | grep history
forward-search-history can be found on "\C-s".
history-search-backward can be found on "\e[5~".
history-search-forward can be found on "\e[6~".
non-incremental-forward-search-history can be found on "\en".
non-incremental-forward-search-history-again is not bound to any keys
non-incremental-reverse-search-history can be found on "\ep".
non-incremental-reverse-search-history-again is not bound to any keys
reverse-search-history can be found on "\C-r".
在我的情况下,Page-Up / Down也可用于搜索以我已输入的内容开头的命令,如我所配置/etc/inputrc
:
# Page Up/Down cycles through history only for matching entries
"\e[5~": history-search-backward # Previous
"\e[6~": history-search-forward # Next