bug-findutils
[Top][All Lists]
Advanced

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

Re: recursive find in current and parent etc until an item is found


From: Peng Yu
Subject: Re: recursive find in current and parent etc until an item is found
Date: Sun, 12 Apr 2020 14:12:38 -0500

OK. So this will make sure `/d1/d2/d3` will not be searched multiple
times? Or it is still searched when `/d1/d2`, `/d1` or `/` is
searched?

On 4/12/20, Bernhard Voelker <address@hidden> wrote:
> On 2020-04-11 12:19, Peng Yu wrote:
>> Recursive also means subdirectories, sub subdirectories, etc.
>
> ah, so you want to fall back for the search to the parent and all
> parent directories.  E.g. if you are in
>   /d1/d2/d3
> then you want to search in
>   /d1/d2/d3
> falling back to
>   /d1/d2
> and
>   /d1
> and
>   /
> right?
>
> Then you just need to convert $PWD accordingly and pass it
> to one find invocation.  Maybe something like this?
>
> ---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
> #!/bin/sh
>
> f="$1" \
>   && test -n "$f" \
>   || { echo "Usage: $0 FILE" >&2; exit 1; }
>
> # Expand "/d1/d2/d3" into "/d1/d2/d3  /d1/d2  /d1  /".
> sedSplitDirs='
>   :a # loop target.
>   # handle end of loop: append slash, print + quit.
>   /^$/ {
>     c\
> /
>     p; q};
>     # Print each line.
>     p
>     # Then strip off trailing dir ...
>     s|/[^/]*$||;
>     # ... and jump to :a.
>     ta
> '
>
> find -H $( pwd | sed "$sedSplitDirs" ) -name "$f" -ls -quit
> --->8--->8--->8--->8--->8--->8--->8--->8--->8--->8--->8---
>
> Have a nice day,
> Berny
>


-- 
Regards,
Peng



reply via email to

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