Celeb Glow
news | March 11, 2026

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.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 Answer

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
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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