bash 查找错误 - 未知主要或运算符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45313672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find error - unknown primary or operator
提问by James Trory
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iname -iregex '.*_OUTPUT' -exec rsync -rtWv --stats --progress {} /Volumes/COMMON-LIC-PHOTO/ASPERA/ASPERA_STAGING/ \;
The code above is designed to look inside the directory Completefor any sub-directories with the phrase "_OUTPUT" (ignoring case, hence -iname
) at the end of the directory name and copy what it finds to a new location, Aspera_Staging. I'm running the code in a .sh triggered by the launchcd app Launch Control whenever a new directory is moved to Complete(which could be part of the issue because cron seems to be very picky).
上面的代码旨在查看Complete-iname
目录中目录名称末尾带有短语“_OUTPUT”(因此忽略大小写)的任何子目录,并将找到的内容复制到新位置Aspera_Staging。每当将新目录移动到Complete时,我都会在由 launchcd 应用程序 Launch Control 触发的 .sh 中运行代码(这可能是问题的一部分,因为 cron 似乎非常挑剔)。
It works about half the time, the other half it does nothing at all. An OUTPUT directory won't be copied. I can't find a pattern, it almost seems random. I've noticed in the debug log that it is giving me the following error:
它大约有一半的时间有效,另一半则什么也不做。OUTPUT 目录不会被复制。我找不到模式,它几乎看起来是随机的。我在调试日志中注意到它给了我以下错误:
find: .*_OUTPUT: unknown primary or operator
查找:.*_OUTPUT:未知的主要或运算符
I've spent hours tinkering, trying to figure it out. I've followed a lot of suggestions found on here and other sites but so far nothing has worked. It obviously has something to do with it looking for the Output folders but I just can't get to the bottom of it.
我花了几个小时修修补补,试图弄清楚。我遵循了在这里和其他网站上找到的很多建议,但到目前为止没有任何效果。它显然与寻找输出文件夹有关,但我无法深入了解它。
回答by xhienne
As commenters have noticed, -iname
requires a parameter, therefore the -iregex
that follows is understood as that parameter and the parameter to -iregex
is (mis)taken as an operator, hence your error message.
正如评论者所注意到的,-iname
需要一个参数,因此-iregex
后面的被理解为该参数,而参数 to-iregex
被(错误)视为运算符,因此您的错误消息。
In your context, -iname
and -iregex
seem redundant, so your command should be either:
在您的上下文中,-iname
并且-iregex
似乎是多余的,因此您的命令应该是:
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iname '*_OUTPUT' -exec ... \;
or:
或者:
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iregex '.*_OUTPUT' -exec ... \;
(notice how the parameters to -iname
and to -iregex
slightly differ)
(注意参数 to-iname
和 to-iregex
略有不同)