help-bash
[Top][All Lists]
Advanced

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

Re: small gnu find question


From: Greg Wooledge
Subject: Re: small gnu find question
Date: Sun, 10 Oct 2021 09:32:59 -0400

On Sun, Oct 10, 2021 at 01:35:46PM +0200, Alex fxmbsw7 Ratchev wrote:
> do i need the second last statement, the -o, there ?
> 
>    find \
>     "${pos[@]}" \
>      \( -name '*.off' -o -name '*.old' -o -name '*.old.*' -o -name
> '*.off.*' -o -name '*.sw[a-z]' \) -prune -o \
>      -printf '%Y\0%s\0%m\0%T@\0%f\0%p\0\0'

You're basically asking how find's -prune switch works.  Or why it works
the way it does.  (By the way, this is a POSIX feature, not a GNUism.)

Here's how POSIX documents it:

       -prune    The  primary  shall  always  evaluate as true; it shall cause
                 find not to descend the current pathname if it  is  a  direc‐
                 tory.  If the -depth primary is specified, the -prune primary
                 shall have no effect.

Here's how GNU documents it, in the man page:

       -prune True;  if  the  file is a directory, do not descend into it.  If
              -depth is given, then -prune has no effect.  Because -delete im‐
              plies  -depth,  you  cannot  usefully use -prune and -delete to‐
              gether.  For example, to skip the directory  src/emacs  and  all
              files and directories under it, and print the names of the other
              files found, do something like this:
                  find . -path ./src/emacs -prune -o -print

And here's a piece of the GNU info page, which is pretty hard to locate,
because there are roughly a dozen different hits on -prune before we
finally get to this one:

 -- Action: -prune
     If the file is a directory, do not descend into it.  The result is
     true.  For example, to skip the directory 'src/emacs' and all files
     and directories under it, and print the names of the other files
     found:

          find . -wholename './src/emacs' -prune -o -print

     The above command will not print './src/emacs' among its list of
     results.  This however is not due to the effect of the '-prune'
     action (which only prevents further descent, it doesn't make sure
     we ignore that item).  Instead, this effect is due to the use of
     '-o'.  Since the left hand side of the "or" condition has succeeded
     for './src/emacs', it is not necessary to evaluate the
     right-hand-side ('-print') at all for this particular file.



reply via email to

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