“发现:path必须在expression式之前:”我如何指定一个recursionsearch,也可以find当前目录中的文件?

我很难find当前目录中的匹配以及其子目录。

当我运行find *test.c ,它只会给我当前目录中的匹配项。 (不在子目录中查看)

如果我尝试find . -name *test.c find . -name *test.c我期望得到相同的结果,但是它只给出了我在子目录中的匹配项。 当有工作目录中应该匹配的文件时,它会给我: find: paths must precede expression: mytest.c

这个错误是什么意思,我怎样才能从当前目录及其子目录中获得匹配?

尝试把它放在引号中 – 你正在运行到shell的通配符扩展中,所以你通过传递来查找的结果如下所示:

 find . -name bobtest.c cattest.c snowtest.c 

导致语法错误 所以试试这个:

 find . -name '*test.c' 

注意文件expression式的单引号 – 这些将会停止扩展通配符的shell(bash)。

发生了什么事是shell将“* test.c”扩展为文件列表。 尝试逃避星号:

 find . -name \*test.c 

尝试把它放在引号中:

 find . -name '*test.c' 

从查找手册:

 NON-BUGS Operator precedence surprises The command find . -name afile -o -name bfile -print will never print afile because this is actually equivalent to find . -name afile -o \( -name bfile -a -print \). Remember that the precedence of -a is higher than that of -o and when there is no operator specified between tests, -a is assumed. “paths must precede expression” error message $ find . -name *.c -print find: paths must precede expression Usage: find [-H] [-L] [-P] [-Olevel] [-D ... [path...] [expression] This happens because *.c has been expanded by the shell resulting in find actually receiving a command line like this: find . -name frcode.c locate.c word_io.c -print That command is of course not going to work. Instead of doing things this way, you should enclose the pattern in quotes or escape the wildcard: $ find . -name '*.c' -print $ find . -name \*.c -print