你如何通过生活在许多不同目录中的代码?

joe*_*ker 18 python grep zope plone

我正在研究一种大量使用鸡蛋的Python程序(Plone).这意味着有198个目录充满了我可能想要在调试时搜索的Python代码.有没有一种很好的方法只搜索那些目录中的.py文件,避免不相关的代码和大型二进制文件?

Ste*_* B. 23

find DIRECTORY -name "*.py" | xargs grep PATTERN
Run Code Online (Sandbox Code Playgroud)

顺便说一句,因为写这个,我发现ACK,这是一个更好的解决方案.

(自那次编辑以来,我发现了ag).

  • 找到DIRECTORY -name'*.py'-exec grep PATTERN {} + (3认同)

Bri*_*new 18

我强烈推荐ack,一个grep替代品,"针对具有大量异构源代码树的程序员"(来自网站)


mon*_*ker 16

grep -r -n "PATTERN" --include="*.py" DIRECTORY
Run Code Online (Sandbox Code Playgroud)


Mar*_*ent 6

这些天我也经常使用ack.我做了一点调整以找到所有相关的文件类型:

# Add zcml to the xml type:
--type-add
xml=.zcml

# Add more files the plone type:
--type-add
plone=.dtml,.zpt,.kss,.vpy,.props

# buildout config files
--type-set
buildout=.cfg

# Include our page templates to the html type so we can limit our search:
--type-add
html=.pt,.zpt

# Create txt file type:
--type-set
txt=.txt,.rst

# Define i18n file types:
--type-set
i18n=.pot,.po

# More options
--follow
--ignore-case
--nogroup
Run Code Online (Sandbox Code Playgroud)

重要的是要记住,如果扩展名不在其配置中,ack将无法找到文件.有关所有可用类型,请参阅"ack --help-types".

我还假设你正在使用煎蛋,所以你可以grep/ack /找到所有相关的文件?