Linux find 不递归查找

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15931248/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:41:07  来源:igfitidea点击:

find does not find recursively

linuxshellfind

提问by Sean Xiao

I'm in directory "home" and I run this command

我在目录“home”中,我运行这个命令

find . -iname *.mov

and it produces

它产生

./root/movies/Corey/holtorf/Intro.mov

Now, I "cd .." and run the same command

现在,我“cd ..”并运行相同的命令

find . -iname *.mov

This time "Intro.mov" is not in the result. What are the reasoning behind this? And what is the command to search recursively for every file ending with ".mov" in the current directory? Thanks.

这次“Intro.mov”不在结果中。这背后的原因是什么?递归搜索当前目录中每个以“.mov”结尾的文件的命令是什么?谢谢。

采纳答案by ypnos

When using a wildcard in an argument it is expanded by the shell. To prevent this, you need to write "*.mov".

在参数中使用通配符时,它会被 shell 扩展。为了防止这种情况,您需要编写“*.mov”。

In your case, the shell expands to whatever files it finds beforepassing the argument to find, which then gets a list of files and will not search based on the original pattern.

在您的情况下,shell将参数传递给 find之前扩展到它找到的任何文件,然后获取文件列表并且不会根据原始模式进行搜索。

回答by dogbane

You might need to add -followif your home directory is actually a symlink. Also quote the pattern otherwise the shell will try to expand it before passing it to find.

-follow如果您的主目录实际上是一个符号链接,您可能需要添加。还要引用该模式,否则 shell 将在将其传递给find.

find . -iname "*.mov" -follow

回答by Kenneth P. Hough

I cannot comment yet so I will post this as an answer (my apologies in advance).

我还不能发表评论,所以我会将此作为答案发布(我提前道歉)。

Please check out this post "find: paths must precede expression:" How do I specify a recursive search that also finds files in the current directory?

请查看这篇文章“查找:路径必须先于表达式:”我如何指定一个递归搜索来查找当前目录中的文件?

And additional information that may benefit you: To recursively find a file with a certain name in your current directory, you can use either grep or find

以及可能有益于您的其他信息:要在当前目录中递归查找具有特定名称的文件,您可以使用 grep 或 find

grep -r "*.mov" .

or for case-insensitive search

或不区分大小写的搜索

grep -ri "*.mov" .

and for find

并找到

find . -type f -exec grep -l "*.mov" {} +

Also a useful link http://www.cyberciti.biz/faq/howto-recursively-search-all-files-for-words/

还有一个有用的链接http://www.cyberciti.biz/faq/howto-recursively-search-all-files-for-words/

回答by Supplement

I would use:

我会用:

 grep -rn 'mov' .

recursive numeric search

递归数字搜索