19

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

0

5 Answers 5

26
find . -type d -not \( -name .svn -prune \)
5
  • I'll go with this one, though they all seemed to work.
    – Jason Down
    Jun 29, 2009 at 15:44
  • I've used -prune on find before, but I hadn't seen that \( ... \) trick. Thanks. Jun 29, 2009 at 16:40
  • 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, 2012 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, 2013 at 18:31
  • Would this work without the -type d? I like to search for all file but exclude the ".git" dir recursively Apr 21, 2013 at 17:55
5

What about simply

find . -type d |  grep -v '.svn'
3
  • Loses your ability to use any of the find actions. Jun 29, 2009 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, 2009 at 19:22
  • That way you also exclude files with the pattern, not only folders and sub-folders of the offending folder.
    – Ocean
    Mar 25, 2022 at 21:14
5

What about the -path option to find?

find . -type d ! -path '*.svn*'
1
  • 1
    Missed off a closing quote. There's an outside chance that the wildcards might be too greedy.
    – Dan Carley
    Jun 29, 2009 at 15:37
3

You could use:

find . -type d -not -wholename '*.svn*' 
1
  • 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, 2010 at 18:38
2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .