1

I tried to use this command in my work dir

find . -type d  \( ! -name .git  -prune \) -o \( ! -name .hg  -prune \)

Does not seem to work?

removing prune will only exclude .git or .hg directories, not their subdir

est
  • 10,087
  • 10
  • 63
  • 112

2 Answers2

4
find . \( -name .git -o -name .hg \) -prune -o -type d -print
Barmar
  • 596,455
  • 48
  • 393
  • 495
2

My answer is essentially the same as @Barmar's, which I have upvoted:

find . \( -name .git -o -name .hg \) -prune -o \( -type d -print \)

A little explanation about this command might be helpful to you:

Here -o means OR. When find finds a file's name matching .git or .hg, it stops the further search due to -prune option and evaluates to true, hence skips the other -o branch(which is directory printing). That's why only those directories not containing .git or .hg will show up.

You may also refer to this question on SO: How to use '-prune' option of 'find' in sh?

Community
  • 1
  • 1
Hui Zheng
  • 9,306
  • 2
  • 29
  • 37