The correct way to use find prune
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.cThis 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.cThere 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" -printPlease help.
1 Answer
Your command
find . -path '*/.svn' -prune -o -name "*.c" -printshould indeed work, though you might rewrite it
find . -name .svn -prune -o -name "*.c" -printotherwise your find is broken. I tried on 2 versions find --version:
find (GNU findutils) 4.5.12
find (GNU findutils) 4.4.2 3