【发布时间】:2013-09-27 16:46:06
【问题描述】:
在我的fetch/evs/ 下,没有子文件夹,我有一个命令应该列出fetch/evs/*.ev 的所有不包含文本' Error 的文件:
find . -ipath '*/fetch/evs/*.ev' | xargs grep -L -e "' Error" > try0.txt
此命令返回 692 个文件。奇怪的是它忽略了满足条件的文件的一部分,例如,如果我这样做:
find . -ipath '*/fetch/evs/grades*.ev' | xargs grep -L -e "' Error" > try1.txt
此命令返回 72 个文件,它们根本不在 try0.txt 中。
我真的无法理解...有人可以帮忙吗?
Edit1:我才意识到我遗漏了一个非常重要的信息,实际上是在命令之后引发了一条消息:xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option。该命令在名称包含' 的文件处停止执行。为了纠正这个问题,我尝试了:
find . -ipath '*/fetch/evs/*.ev' | xargs -0 grep -L -e "' Error" > try3.txt
返回 xargs: argument line too long 和 0 个文件。
我也试过了:
find . -ipath '*/fetch/evs/*.ev' -print0 | xargs -0 grep -L -e "' Error" > try4.txt
根本停不下来....
有人知道吗?
【问题讨论】:
-
可能是因为文件名中有空格。试试
find . -ipath '*/fetch/evs/*.ev' -print0 | xargs -0 grep -L -e "' Error" > try0.txt。有用吗? -
为什么不使用
grep和-l切换来列出匹配的文件? -
抱歉,我的意思是“不”包含...
-
返回
-print0、xargs: Warning: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option?和xargs: argument line too long... -
顺便说一下,没有文件名包含空格...
标签: bash shell grep find xargs