我想在app
目錄內搜索字符串foo
,但不包括文件名中包含migrations
的任何文件。我預計今年grep
命令工作grep with --include和--exclude
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或如果他們根本不工作在一起。
在文件名中。 –