Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm running MacOSX 10.5.8

I run the following:

~/Sites/jjprof/trunk/content > find . -type d -name '*svn' -prune
./.svn
./resources/.svn
./resources/sitewide/.svn
./temporary/.svn
./users/.svn
./users/avatars/.svn

I would expect this command to ignore all the .svn subdirectories; instead it displays them.

find . -name '*svn' -prune 

does the same thing.

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Try this:

find -type d -path '.svn' -prune -o -print

From man find under the section on -name:

To ignore a directory and the files under it, use -prune; see an example in the description of
-path.

Under the section on -path:

To ignore a whole directory tree, use -prune rather than checking every file in the tree. 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

From the "Examples" section:

However, the -prune action itself returns true, so the following -o ensures that the right hand side is evaluated only for those directories which didn't get pruned (the contents of the pruned directories are not even visited, so their contents are irrelevant).

share|improve this answer
1  
This is indeed the right way to use -prune, and a good explanation. However, -name .svn is the right way to select .svn subdirectories (-name '*svn' or -path '*svn'` would match extra files). –  Gilles Nov 4 '10 at 21:17
1  
This does not in fact work. You need to use '*/.svn' as the path name; otherwise, it will not match ./.svn, ./subdir/svn, and so forth. –  Brooks Moses Jan 12 '11 at 0:13

find manual states tha prune "ignores the preceding path ..." so the command should be

find . -prune -type d -name '*svn'

This is because you can have something like

find -path . -name '*svn' -o -path './notimportantdir' -prune

which finds '*svn' in current path except those under notimportantdir

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.