bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The quickest way to not to descend into sub-directories once a file


From: Bernhard Voelker
Subject: Re: The quickest way to not to descend into sub-directories once a file is found?
Date: Wed, 2 Oct 2019 23:25:50 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0

On 2019-09-27 17:26, Peng Yu wrote:
> On 2019-09-27 09:49, Stephane Chazelas wrote:
>> Here, you could do:
>>
>> find . -type d -exec test -e '{}/file.txt' \; -prune -printf '%p/file.txt\n'
>>
>> But note that it involves forking a process and executing a test
>> command in it for each non-pruned directory, which may end-up
>> being less efficient than traversing the directories that a
>> file.txt in them.

[...]

> But wouldn't a scripting language be less efficient than C implementation?

There's a saying in the computing world:
"premature optimization is the root of all evil".

Actually, Stephane's example is similar to what is documented
for a similar case here:

https://www.gnu.org/software/findutils/manual/html_node/find_html/Finding-the-Shallowest-Instance.html

I don't think one exec per directory is that bad.
Please check (and report numbers in case of extraordinarily slow performance).

Have a nice day,
Berny



reply via email to

[Prev in Thread] Current Thread [Next in Thread]