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
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
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?