“查找:路径必须在表达式之前:"如何指定在当前目录中也可以找到文件的递归搜索? [英] "find: paths must precede expression:" How do I specify a recursive search that also finds files in the current directory?

查看:13
本文介绍了“查找:路径必须在表达式之前:"如何指定在当前目录中也可以找到文件的递归搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让 find 在当前目录及其子目录中查找匹配项.

I am having a hard time getting find to look for matches in the current directory as well as its subdirectories.

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

When I run find *test.c it only gives me the matches in the current directory. (does not look in subdirectories)

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

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?

推荐答案

试着把它放在引号里——你遇到了 shell 的通配符扩展,所以你实际传递给 find 的内容如下所示:

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:

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

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

...causing the syntax error. So try this instead:

find . -name '*test.c'

注意文件表达式周围的单引号——它们会阻止 shell (bash) 扩展你的通配符.

Note the single quotes around your file expression -- these will stop the shell (bash) expanding your wildcards.

这篇关于“查找:路径必须在表达式之前:"如何指定在当前目录中也可以找到文件的递归搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆