From: Thomas 'PointedEars' Lahn on
Jerry Fleming wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Jerry Fleming wrote:
>>> I want to use find to list my files, but exclude those in a directory
>>> containing a certain file. [...] I was wondering how to achieve the same
>>> effect using find.
>>
>> find $PATHS \
>> -path $(find $PATHS -type d -exec test -e "{}/$FILE" \; -print) \
>> -prune -o -print
>>
>> should work (tested on Debian) if there is only one directory below
>> $PATHS containing a file with name $FILE. You can perhaps use sed(1) or
>> awk(1) to generate several -path expressions if there is more than one
>> directory.
>
> Thanks. That does the trick. But I was wondering if there is anything
> builtin to find that can do the same thing. It turns out both -name and
> -path test only the current file system entry been stat'ed. Is there
> anything in find to conditionally -prune a directory based on its content?

I don't think it gets any more built-in than
<news:1321855.v0bhDfK2Jl(a)PointedEars.de>.

Please trim your quotes to the relevant minimum, don't quote signatures.

--
PointedEars
From: Stephane CHAZELAS on
2010-05-14, 17:41(+02), Thomas 'PointedEars' Lahn:
[...]
>> find . -type d -exec sh -c '[ -e "$1/file" ]' sh {} \; -prune -o ...
>
> Clever solution, but ISTM this can be simplified to
>
> find . -type d -exec sh -c '[ -e "$1/file" ]' : '{}' \; -prune -o ...
>
> then
>
> find . -type d -exec sh -c '[ -e "$0/file" ]' '{}' \; -prune -o ...

Yes, though it's a hack with some potential issues: like the
error messages from "sh", if any will look like:

../this/dir: error...

instead of:

sh: error...


> and then
>
> find . -type d -exec test -e '{}/file' \; -prune -o ...

no, won't work with many "find"s and is not standard.

{} has to be an argument to find on its own for it to be
portably recognised by find.

> You may also use
>
> find . -type d -exec [ -e '{}/file' ] \; -prune -o ...
[...]

same as above.


--
Stéphane
From: Jerry Fleming on
On 2010-05-14 23:41, Thomas 'PointedEars' Lahn wrote:
> Stephane CHAZELAS wrote:
>
>> Jerry Fleming wrote:
>> [...]
>>> I want to use find to list my files, but exclude those in a directory
>>> containing a certain file.
>> [...]
>>
>> find . -type d -exec sh -c '[ -e "$1/file" ]' sh {} \; -prune -o ...
>
> Clever solution, but ISTM this can be simplified to
>
> find . -type d -exec sh -c '[ -e "$1/file" ]' : '{}' \; -prune -o ...
>
> then
>
> find . -type d -exec sh -c '[ -e "$0/file" ]' '{}' \; -prune -o ...
>
> and then
>
> find . -type d -exec test -e '{}/file' \; -prune -o ...
>
> You may also use
>
> find . -type d -exec [ -e '{}/file' ] \; -prune -o ...
>
> instead.
>
>
> PointedEars

That's really helpful. Thanks a lot.