1

Facing the same problem as Why doesn't 'find' prune the way I think it should?,

but that accepted answer doesn't work for me:

Here are my files:

$ find . 
.
./resources
./resources/sitewide
./resources/sitewide/test.c
./resources/sitewide/.svn
./resources/sitewide/.svn/test.c
./resources/test.c
./resources/.svn
./resources/.svn/test.c
./test.c
./users
./users/avatars
./users/avatars/test.c
./users/avatars/.svn
./users/avatars/.svn/test.c
./users/test.c
./users/.svn
./users/.svn/test.c
./temporary
./temporary/test.c
./temporary/.svn
./temporary/.svn/test.c
./.svn
./.svn/test.c

This is what the result is when using the accepted answer:

$ find -type d -path '.svn' -prune -o -print
.
./resources
./resources/sitewide
./resources/sitewide/test.c
./resources/sitewide/.svn
./resources/sitewide/.svn/test.c
./resources/test.c
./resources/.svn
./resources/.svn/test.c
./test.c
./users
./users/avatars
./users/avatars/test.c
./users/avatars/.svn
./users/avatars/.svn/test.c
./users/test.c
./users/.svn
./users/.svn/test.c
./temporary
./temporary/test.c
./temporary/.svn
./temporary/.svn/test.c
./.svn
./.svn/test.c

There are two problem with the accepted answer, first the .svn are still listed, and second, not only directories but files are also listed.

These problems I actually can fix. but my question is,

how to find those .c files not under .svn directories?

I've tried all the following but nothing worked for me:

 find .  -path '*/.svn' -prune -name "*.c" -print
 find .  -path '*/.svn' -prune -o -name "*.c" -print
 find .  -path '*/.svn' -prune -name "*.c" -o -print
 find .  -path '*/.svn' -prune -a -name "*.c" -print

Please help.

1

Your command

find .  -path '*/.svn' -prune -o -name "*.c" -print

should indeed work, though you might rewrite it

find .  -name .svn -prune -o -name "*.c" -print

otherwise your find is broken. I tried on 2 versions find --version:

find (GNU findutils) 4.5.12
find (GNU findutils) 4.4.2
  • 1
    Thanks meuh. More Q: The command that I actually ran was "find . \( -type f -o -type l \) -path '*/.svn' -prune -o -name "*.c" -print", but I remove that \( -type f -o -type l \) part to simplify my question (I also tried to put a -o before -path). Now I realize it is that part that is giving me the problem. Please add your answer to that as well. Thanks. – xpt Aug 11 '15 at 14:26
  • 1
    Ah, got it -- find . -name .svn -prune -o \( -type f -o -type l \) -name "*.c" -print – xpt Aug 11 '15 at 14:32
  • @xpt glad you found how to do what you wanted. The syntax is fairly painful. I find it useful to think there's an implied -a between all options and that and binds tighter than or. – meuh Aug 11 '15 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.