如何使用Unix快速搜索我的代码? [英] How can I quickly search my code using unix?
问题描述
我经常在我的整个代码库中搜索令牌,也许是函数名称.我的传统方法是使用grep这个词本身.但是,代码库太大,以至于我无法高效地执行此操作(需要几分钟).
I frequently search for a token, perhaps a function name, throughout my codebase. My traditional method would be to grep for the term itself. However, the codebase is so large that I can't do this efficiently (it takes minutes).
有没有办法有效地做到这一点?
Is there a way to do this efficiently?
ack(忽略诸如修订控制文件之类的irrelevent文件)仍然太慢. ctags只找到声明,这不是我所需要的.我以为strigi可能有用,但我还没有尝试过.
ack (which ignores irrelevent files such as revision control files) is still too slow. ctags only finds declarations, which isn't what I need. I thought something like strigi might work, but I haven't tried it.
我在Linux上,使用vim和GNU工具链,在很大程度上是C ++代码库.
I'm on linux, using vim and the GNU toolchain, on a largely C++ codebase.
推荐答案
使用find
和fgrep
.体面的find
将把该集合限制为符合某些条件的文件,而fgrep
将在每个文件中进行搜索.请注意,fgrep
将比grep
快.
Use find
and fgrep
. A decent find
will restrict the set to files matching some set of criteria, and fgrep
will search within each file. Note that fgrep
will be faster than grep
.
您还可以使用IDE的代码索引功能.例如,Eclipse将允许您转到函数的声明,并在工作时在后台构建相关的集合.甚至vim 7都具有一些这样的功能,尽管我不记得确切的代码完成功能.
You could also use an IDE's code indexing features. For example, Eclipse will allow you to go to a function's declaration, and it builds the relevant set in the background while you work. Even vim 7 has some such features, although I don't remember exactly what it does beyond code completion.
这篇关于如何使用Unix快速搜索我的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!