Monday, March 9, 2009

051 通过Control+R 查找历史记录

我非常相信这是你最常用的有关history的功能。你可能已经运行了一个非常长的命令,接下来当你要再次执行这个命令的时候你只需要搜索历史记录,找到它并重新执行就可以了。只要执行Control+R然后输入查找关键字就可以查找到历史命令了。
在下面的例子中我通过'red'关键字进行查找,查找结果是包含这个关键字的cat /etc/redhat-release命令:
# [注意: 键入Ctrl+R 将显示一个如下的 reverse-i-search 窗口] 

(reverse-i-search)'red': cat /etc/redhat-release
[Note: Press enter when you see your command, which
will execute the command from the history]

# cat /etc/redhat-release
Fedora release 9 (Sulphur)

有时候,你可能希望先编辑一下原来的命令然后再执行它。比如你查找httpd关键字,结果显示了service httpd stop命令,然后你可以把stop改成start然后再执行它。
# [注意: 键入Ctrl+R 将显示一个如下的 reverse-i-search 窗口]  
(reverse-i-search)`httpd': service httpd stop
[Note: Press either left arrow or right arrow key when
you see your command, which will display the command
for you to edit, before executing it]

# service httpd start

No comments:

Post a Comment