Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm trying to use the Linux find command to find all directories and sub-directories that do not have .svn (Subversion hidden folders) in their path. I can only get it to exclude the actual .svn directories themselves, but not any of the sub-directories.

Here is what I'm doing right now:

find . -type d \! -iname '*.svn*'

I've also tried:

find . -type d \! iname '.svn' \! iname '.svn/*'

Just an FYI, I'm trying to use the find pattern so I can apply some subversion properties to all directories in my repository excluding the subversion hidden folders and their sub-directories (by applying the exec command to the directories returned from the find command)..

TIA

share|improve this question

5 Answers 5

up vote 21 down vote accepted
find . -type d -not \( -name .svn -prune \)
share|improve this answer
    
I'll go with this one, though they all seemed to work. –  Jason Down Jun 29 '09 at 15:44
    
I've used -prune on find before, but I hadn't seen that \( ... \) trick. Thanks. –  Rory Jun 29 '09 at 16:40
    
Works like a charm :) Thanks! –  Piskvor Feb 8 '10 at 16:03
    
Can you tell how this would work in a node.js / express app where I want to exclude node-modules from counting the lines? I tried find . -name '*.js' -not \( -name 'node_modules' -prune \) | xargs wc -l without success ... –  shredding Oct 15 '12 at 7:26
    
In response to @shredding regarding Node.js / Express apps and excluding node_modules directories from find's results, this works for me: find . -name '.test.js' -not (-wholename '*node_modules' ) ... given that the tests i want to run are suffixed with ".test.js" –  mysterlune Apr 1 '13 at 18:31

What about simply

find . -type d |  grep -v '.svn'
share|improve this answer
    
Loses your ability to use any of the find actions. –  David Pashley Jun 29 '09 at 15:45
    
Yes, but what about a nice little sh loop instead? :) for FILE in find . -type d | grep -v '.svn'; do echo whatever; done –  wazoox Jun 29 '09 at 19:22

What about the -path option to find?

find . -type d ! -path '*.svn*'
share|improve this answer
1  
Missed off a closing quote. There's an outside chance that the wildcards might be too greedy. –  Dan Carley Jun 29 '09 at 15:37

find . -path './tmp' -prune -o .......

share|improve this answer

You could use:

find . -type d -not -wholename '*.svn*' 
share|improve this answer
    
it stripped the * from the front of the answer... should be find . -type d -not -wholename '/.svn/' (that's wholename squote asterisk slash dot svn slash asterisk squote) –  TechFriend Jul 29 '10 at 18:38

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.