UNIX命令行中类似Matlab的命令历史记录检索 [英] Matlab-like command history retrieval in unix command line
问题描述
在Matlab中,有一个我非常喜欢的功能.假设我键入了命令very-long-command
,然后输入了几个命令.然后,如果以后再次需要长命令,只需键入very
并按向上箭头键,我的长命令就会出现.它找到以very
开头的最后一条命令.我无法在UNIX命令行中执行相同的操作,当我尝试执行此操作时,它会忽略我键入的内容,并按时间顺序返回到最后一个命令.有办法吗?
In Matlab, there is a very nice feature that I like. Suppose I typed the command very-long-command
and then a few several commands afterwards. Then later if I need the long command again, I just type very
and press the up arrow key, my long command appears. It finds the last command that starts with very
. I couldn't do the same in unix command line, when I try to do it, it disregards whatever I typed, and goes back to the last commands in chronological order. Is there a way to do it?
推荐答案
在bash中,点击 ctrl - r 可以进行历史搜索:
In bash, hitting ctrl-r will let you do a history search:
$ echo 'something very long'
something very long
$ # blah
$ # many commands later...
(reverse-i-search)`ec': echo 'something very long'
在上面的代码段中,我在# many commands later...
之后的下一行中击 ctrl - r ,然后键入 e c ,这使我回到了echo命令.此时,按 Enter 将执行命令.
In the above snippet, I hit ctrl-r on the next line after # many commands later...
, and then typed ec which brought me back to the echo command. At that point hitting Enter will execute the command.
这篇关于UNIX命令行中类似Matlab的命令历史记录检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!