help me out with find command , -prune option

Hi , Kindly help me out .:slight_smile:

i want to find only the file t4 in directory t3. i am in dir t . the tree is as follows.

if i give,

find .
o/p is
.
./t4
./t1
./t1/t2
./t1/t2/t3
./t1/t2/t3/t4
./t1/t2/t4
./t1/t4

directories are like t/t1/t2/t3 and each directory has file t4.
my question is , i want to find file t4 inside directory t3 without looking in to the other sub directories.on for

how will i use -prune option for that?

i want an o/p like this:
./t1/t2/t3/t4

Hope it helps.

find -mindepth 3 -maxdepth 4 -iname "t4"

maxdepth is a GNUism, so if you don't use Linux, or if the depth may be different:

find . -type d -name t3 | xargs -I{} find {} -type f -name t4

or:

find . -type f -name t4 | grep /t3/t4$

thank u for your help. but i need tat o/p using -prune option in find command

Why do you "need" the output using -prune, when other solutions exist?

Hi,
I am learning about -prune option. So only i asked that specifically. Can please give me a samle command which demonstrates the -prune option? ?

this was your ans for my question.

find -mindepth 3 -maxdepth 4 -iname "t4"

But u need not specify maxdepth. the following will work well , which is an alteration of ur ans.

find -mindepth 4 -name "t4"

You don't need prune. Just tell find to only search the directory you require.

find ./t1/t2/t3 -name t4 -print

Output is:
./t1/t2/t3/t4

Hi,
It might seem like hijacking a thread but my question is almost similar so I'm posting it here.
So, taking the tree below
.
./t1
./t1/t2
./t1/t2/t4 ------------------- (1)
./t1/t2/t3
./t1/t2/t3/t4 ------------------- (2)
./t1/t3
./t1/t3/t5/t4 ------------------- (3)
./t1/t3/t5/t6/t4 ------------------- (4)

Similar case, I need to know the directory where t4 files are stored but once t4 is located in a branch { as in (1) } the code should stop descending and should search the next branch for t4 { as shown in (3)}, and again once located should abort searching/descending that branch. Is it possible using 'find'.

Note: In my case the file is an empty file and currently I'm using "find . -name t4 -maxdepth 10 -mindepth 1 -type f -empty -size 0b". The min and max depth are a gamble so I want a solution even when depth is not known. I'm on Linux.

Thanks & Best Regards,