find command: -prune action

find command: -prune action

Post by Dave Bro » Wed, 25 Feb 1998 04:00:00



Not knowing where else to ask about this tool, here goes:

How is the -prune action supposed to work?  The man page
indicates that it should inhibit recursion of a selected
portion of the directory tree.  (Refers to "current directory"...)

I get the impression that I could search the file system for
a file name, but exclude looking into certain directories...
but how?

If I do a "find / -name usr -prune", it won't recurse the
/usr tree, but then, it won't find anything except files
named usr any place else.  Not too useful, that form.

--
Dave Brown   Austin, TX

 
 
 

find command: -prune action

Post by pac.. » Wed, 25 Feb 1998 04:00:00



>Not knowing where else to ask about this tool, here goes:

>How is the -prune action supposed to work?  The man page
>indicates that it should inhibit recursion of a selected
>portion of the directory tree.  (Refers to "current directory"...)

>I get the impression that I could search the file system for
>a file name, but exclude looking into certain directories...
>but how?

>If I do a "find / -name usr -prune", it won't recurse the
>/usr tree, but then, it won't find anything except files
>named usr any place else.  Not too useful, that form.

Probably because you are doing this:

find / -name usr -prune -print

What you don't realize (though it is mentioned in the man page, it is easily
overlooked) is that simple juxtaposition of find actions is equivalent to an
AND operator. So that command means: start from /, look for something named
usr AND don't recurse into it AND print it.

What you want is an OR.

find / -name usr -prune -o -print

which means: start from /, look for something named usr and don't recurse
into it, otherwise print whatever it is you've found.

 
 
 

find command: -prune action

Post by James Youngma » Wed, 25 Feb 1998 04:00:00


  Dave> Not knowing where else to ask about this tool, here goes: How
  Dave> is the -prune action supposed to work?  The man page indicates
  Dave> that it should inhibit recursion of a selected portion of the
  Dave> directory tree.  (Refers to "current directory"...)

  Dave> I get the impression that I could search the file system for a
  Dave> file name, but exclude looking into certain directories...
  Dave> but how?

  Dave> If I do a "find / -name usr -prune", it won't recurse the /usr
  Dave> tree, but then, it won't find anything except files named usr
  Dave> any place else.  Not too useful, that form.

Use either

 find / \( -name  usr -prune \) -o -print
or, better
 find / \( -path /usr -prune \) -o -print

 
 
 

find command: -prune action

Post by William Pa » Thu, 26 Feb 1998 04:00:00


: Not knowing where else to ask about this tool, here goes:

: How is the -prune action supposed to work?  The man page
: indicates that it should inhibit recursion of a selected
: portion of the directory tree.  (Refers to "current directory"...)

: I get the impression that I could search the file system for
: a file name, but exclude looking into certain directories...
: but how?

: If I do a "find / -name usr -prune", it won't recurse the
: /usr tree, but then, it won't find anything except files
: named usr any place else.  Not too useful, that form.

: --
: Dave Brown   Austin, TX

Try
   find / -path /usr -prune -o -print
which is shortcut for
   find / -path /usr -and -prune -or -print
The expression is interpreted using the normal rules of logical OR (-or)
and AND (-and).  AND is evaluated first.

If find comes across /usr, then "-path /usr" is true; and "-prune" will
skip the path, returning also true.  Since "-path /usr -prune" is true,
find will skip to a new path.  However, if find comes across something
other than /usr, then "-path /usr" is false; and "-prune" need not be
tested or acted upon.  Since "-path /usr -prune" is false, "-print" is
evaluated, returning always true and printing the path.

Now, if you want to search for a file name, then try
   find / -path /usr -prune -o -name filename -print

--

 
 
 

1. Complex prune, path expressions in find command

I would like to touch all files outside a few directory trees which have
  ctime later than 3 days ago and mtime earlier than 3 days ago.  This
will make sure that tar will find all files which have been moved since
my last full backup as well as those that have been modified.

It looks like the GNU find command will do this, but I haven't been able
to find the right syntax.  I tried variations on
   find /home/Tom/mydata -ctime -3 -mtime +4 -path 'home/mydata/hda7'
-prune -o -path '/home/Tom/mydata/Program Files' -prune -o -exec touch
{} \; -exec ls {} \;

This command seems to work, except that it does not prune the second
directory.  I have been unable to find a description that I can
understand explaining how prune and path interact, and I am out of ideas
on how to guess the proper syntax.

Can anyone help?

2. Modem diamond supraexpress 56i not working under linux?!

3. find command and pruning

4. filter lines with a specific expression at a specific position

5. Need to find vi command to remove ^H from command man find > find.txt

6. MSG: inetd[132]: nntp/tcp: bind: Address already in use

7. 'find' - can i prune on the basis of pathnames?

8. Telnet login problem?

9. find -prune syntax

10. FIND and PRUNE

11. find -prune Question

12. -prune regexp for gnu find/locate/updatedb doesn't work - why?

13. find...prune & parameter passing including a variable