bug-findutils
[Top][All Lists]
Advanced

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

Re: find - avoiding subtrees & Permission denied messages


From: Bob Proulx
Subject: Re: find - avoiding subtrees & Permission denied messages
Date: Tue, 19 Oct 2010 11:07:43 -0600
User-agent: Mutt/1.5.20 (2009-06-14)

Kevin Buchs wrote:
> I often find myself wanting to use find, but avoid searching any
> subdirectories called .snapshot, which contain our hourly online backups.
> My attempt below seems to fail, for find is trying to access subdirectories
> of .snapshot, for which I have no permission and I get the Permission denied
> messages (many).  I wonder if there is some other trick to avoiding any
> traversal of .snapshot directories anywhere on the tree?  
>
> find ! -path '*/\.snapshot/*' -iname windrv6.inf

Using -prune is a typical way.

  find . -name .snapshot -prune -o -iname windrv6.inf

Bob

Documentation on -prune from the find manual.

 -- 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.  If
     you wanted to print that directory name you could use either an
     extra `-print' action:

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

     or use the comma operator:

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

     If the `-depth' option is in effect, the subdirectories will have
     already been visited in any case.  Hence `-prune' has no effect in
     this case.

     Because `-delete' implies `-depth', using `-prune' in combination
     with `-delete' may well result in the deletion of more files than
     you intended.




reply via email to

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