linux历史命令搜索
因为有些服务器会禁用了ctrl+r命令,所以只能通过设置来实现历史命令的搜索功能,提示工作效率,并且比 ctrl+r 更准确、有效的在历史命令纪录中查找自己想要的命令。具体设置步骤如下所示:
查看自己的机器类型,
1、查看/etc/redhat-release文件是否存在
ll /etc/redhat-release
a. 如果存在, 当前系统是redhat系列的, 包括centos redhat
查看这个文件, 则可以看到当前系统是centos还是redha
b. 如果不存在, 则系统是debian/ubuntu系统
2、查看文件/etc/redhat-release,确认具体是哪种系统
cat /etc/redhat-release
修改配置文件
如果是centos 7,修改 ~/.bashrc 配置;如果是Mac,修改~/.bash_profile 配置,在配置中添加如下内容:
if [[ $- == *i* ]]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
使配置生效
source ~/.bashrc 或者 source ~/.bash_profile
新增.inputrc文件
1、首先在该用户家目录下新建一个 .inputrc 文件,并在其中写入以下配置,如下:
[root@wjoyxt ~]# cat .inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
2、 退出 bash 后重新登陆,输入一个字母或者几个字母,然后 按“上下” 键,就会看到以这个字母搜索到的完整命令行。如果搜索到几个类似命令,通过上下键来切换,有点像 ctrl+r,但是效果不一样。