
| Tips and Tricks: Easy and safe bash history searches |
| 摘自: www.redhatmagazine.com 被阅读次数: 156 |
由 yangyi 于 2008-02-08 21:32:08 提供 |
by an editorContributed by Zak Brown One simple method is to run the history command and pipe it through grep. $ history | grep cat 110 cat /tmp/foo You can then run the command by typing ! and the history line number: $ !110 cat /tmp/foo Another method is to use the built in history search feature. In this case you $ !?cat cat /tmp/foo However, this might be dangerous, what if the last instance of your search term $ !?foo cat /tmp/foo > /dev/hda Ouch! A better solution is to search for the term and append it to your history $ !?foo?:p This will echo the command and place it as the last item in your history without executing. If it is in fact the command you wish to run, just hit the UP ARROW and ENTER 原文链接: http://www.redhatmagazine.com/2008/01/03/tips-and-tricks-easy-and-safe-bash-history-searches/ |