gpt4 book ai didi

grep 与 --include 和 --exclude

转载 作者:行者123 更新时间:2023-12-02 00:32:53 27 4
gpt4 key购买 nike

我想在 app 目录中搜索字符串 foo,但排除文件名中包含 migrations 的任何文件。我希望这个 grep 命令能够工作

grep -Ir --include "*.py" --exclude "*migrations*" foo app/

上面的命令似乎忽略了 --exclude 过滤器。作为替代方案,我可以这样做

grep -Ir --include "*.py" foo app/ | grep -v migrations

这有效,但是结果中 foo 的突出显示丢失了。我还可以将 find 融入其中并保持突出显示。

find app/ -name "*.py" -print0 | xargs -0 grep --exclude "*migrations*" foo

我只是想知道我是否遗漏了 grep 命令行参数组合的某些内容,或者它们是否根本无法一起工作。

最佳答案

我正在寻找 .py 文件上的术语,但不想扫描迁移文件,所以我发现(对于 grep 2.10)如下(我希望这有帮助):

grep -nR --include="*.py" --exclude-dir=migrations whatever_you_are_looking_for . 

关于grep 与 --include 和 --exclude,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14220623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com