简体   繁体   中英

Find files in multiple directories

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.

I am using this but it iterates infinitely:

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

How to get this right?

Try doing this :

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

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

The syntax of your for-loop is incorrect.

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'

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM