“查找:路径必须位于表达式之前:”如何指定同时查找当前目录中文件的递归搜索?
我很难让 find 在当前目录及其子目录中查找匹配项。
当我运行 find *test.c
时,它只提供当前目录中的匹配项。 (不查找子目录)
如果我尝试 find . -name *test.c
我希望得到相同的结果,但它只给我子目录中的匹配项。当工作目录中存在应该匹配的文件时,它会给出: find: paths Must before expression: mytest.c
此错误意味着什么,以及如何从当前的两个文件中获取匹配项目录及其子目录?
I am having a hard time getting find to look for matches in the current directory as well as its subdirectories.
When I run find *test.c
it only gives me the matches in the current directory. (does not look in subdirectories)
If I try find . -name *test.c
I would expect the same results, but instead it gives me only matches that are in a subdirectory. When there are files that should match in the working directory, it gives me: find: paths must precede expression: mytest.c
What does this error mean, and how can I get the matches from both the current directory and its subdirectories?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
尝试将其放在引号中 - 您将遇到 shell 的通配符扩展,因此您实际传递给 find 的内容将如下所示:
...导致语法错误。因此,请尝试以下操作:
注意文件表达式周围的单引号 - 这些将阻止 shell (bash) 扩展通配符。
Try putting it in quotes -- you're running into the shell's wildcard expansion, so what you're acually passing to find will look like:
...causing the syntax error. So try this instead:
Note the single quotes around your file expression -- these will stop the shell (bash) expanding your wildcards.
发生的情况是 shell 将“*test.c”扩展为文件列表。尝试将星号转义为:
What's happening is that the shell is expanding "*test.c" into a list of files. Try escaping the asterisk as:
从查找手册:
From find manual:
尝试将其放在引号中:
Try putting it in quotes:
我看到这个问题已经有了答案。我只是想分享对我有用的东西。我在
(
和-name
之间缺少一个空格。因此,选择文件并排除其中一些文件的正确方法如下所示;I see this question is already answered. I just want to share what worked for me. I was missing a space between
(
and-name
. So, the correct way of chosen files with excluding some of them would be like below;当我试图找到多个文件名时,我遇到了这个问题,这些文件名无法组合成正则表达式,如 @Chris J 的答案中所述,以下是对我有用的
-o
或- or
是逻辑或。请参阅在 Gnu.org 上查找文件< /a> 了解更多信息。我在 CygWin 上运行这个。
I came across this question when I was trying to find multiple filenames that I could not combine into a regular expression as described in @Chris J's answer, here is what worked for me
-o
or-or
is logical OR. See Finding Files on Gnu.org for more information.I was running this on CygWin.
你可以试试这个:
这样,你可以找到所有带有ascii的可读文件,
如果你想指定他的权重和不可执行的文件,可以用cat读取它们:
You can try this:
with that, you can find all readable files with ascii and read them with cat
if you want to specify his weight and no-executable:
当我忘记
(
和-name
之间的空格时,出现此错误。应该是
I got this error when I forgot the space between the
(
and-name
.Should have been
问题在于脚本中如何处理命令替换和管道。您可以简化命令,而无需使用 find 的命令替换。以下是更正后的脚本:
如果您需要使用变量
fbc
,则应使用eval
正确执行命令:这应该可以修复您遇到的错误。
The issue is with how the command substitution and piping are being handled in the script. You can simplify the command without using command substitution for find. Here is the corrected script:
If you need to use the variable
fbc
, you should useeval
to properly execute the command:This should fix the error you're encountering.
就我而言,我在路径中缺少尾随
/
。In my case i was missing trailing
/
in path.