bash 在多个目录中查找文件

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

Find files in multiple directories

linuxbashfind

提问by case

I am using RHEL. In my current folder there are sub folders. I need to find where a file is in the subfolders. The files may be in one or more.

我正在使用 RHEL。在我当前的文件夹中有子文件夹。我需要找到文件在子文件夹中的位置。这些文件可能是一个或多个。

I am using this but it iterates infinitely:

我正在使用它,但它无限迭代:

for f in ./{Failed,Loaded,ToLoad}; do find -name 'file';  done

How to get this right?

如何做到这一点?

回答by Gilles Quenot

Try doing this :

尝试这样做:

find {Failed,Loaded,ToLoad} -name 'file'

if {Failed,Loaded,ToLoad}are really some dirs.

如果{Failed,Loaded,ToLoad}真的是一些目录。

回答by dogbane

The syntax of your for-loop is incorrect.

for 循环的语法不正确。

It should be:

它应该是:

for f in Failed Loaded ToLoad
do
    find "$f" -name 'file'
done

But you don't need a loop. It can simply be done like this:

但是你不需要循环。它可以简单地这样做:

find Failed Loaded ToLoad -name 'file'

回答by codeforester

findcan take multiple arguments for source directory. So, you could use:

find可以为源目录采用多个参数。所以,你可以使用:

find Failed Loaded ToLoad -name 'file' ...

You don't need a loop. This can be handy if you want findto look at a subset of your subdirectories.

你不需要循环。如果您想find查看子目录的子集,这会很方便。