重击:选择与模式匹配的上一个命令 [英] Bash: select a previous command that matches a pattern

查看:62
本文介绍了重击:选择与模式匹配的上一个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解有关使用上下箭头的bash历史记录导航.

I know about the bash history navigation with the Up and Down arrows.

我想以一种懒惰的方式来选择与某些正则表达式匹配的前一个命令(该命令比整个命令短,因此键入时间更少).

I would like a lazy way to select a previous command that matches some regex (that is shorter than the whole command, so it takes less time to be typed).

bash有可能吗?

如果没有,其他外壳程序是否具有这种功能?

If not, do other shells have such a feature?

推荐答案

您始终可以使用CTRL-R向后搜索历史记录,并键入上一个命令的某些部分.再次点击CTRL-R(在第一次点击后)会重复您的查询(跳到下一个匹配项).

You can always use CTRL-R to search your history backward, and type some part of the previous command. Hitting CTRL-R again (after the first hit) repeats your query (jumps to the next match if any).

我个人将其用于正则表达式搜索(因为尚无法进行正则表达式搜索(AFAIK)):

Personally I use this for regex search (as regex searching is not possible yet (AFAIK)):

# search (using perl regexp syntax) your entire history
function histgrep()
{
     grep -P $@ ~/.bash_history
}   

有关通过该功能搜索最新历史记录项的信息,请参见

For searching most recent history items via that function, see this (on setting $PROMPT_COMMAND ).

这篇关于重击:选择与模式匹配的上一个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆