18

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

Avery Payne
  • 14,326
  • 1
  • 48
  • 87
Jason Down
  • 303
  • 1
  • 6
  • 11

5 Answers5

26
find . -type d -not \( -name .svn -prune \)
Dan Carley
  • 25,189
  • 5
  • 52
  • 70
  • 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. – Amandasaurus Jun 29 '09 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 '12 at 07: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 01 '13 at 18:31
  • Would this work without the `-type d`? I like to search for all file but exclude the ".git" dir recursively – James Mitch Apr 21 '13 at 17:55
5

What about simply

find . -type d |  grep -v '.svn'
wazoox
  • 6,782
  • 4
  • 30
  • 62
5

What about the -path option to find?

find . -type d ! -path '*.svn*'
Amandasaurus
  • 30,211
  • 62
  • 184
  • 246
2

You could use:

find . -type d -not -wholename '*.svn*' 
idbrii
  • 153
  • 1
  • 5
  • 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) –  Jul 29 '10 at 18:38
2

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