Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This command is not DWIM-compliant:

find . \( -name .svn -prune -false \) -o \( -empty -delete \)
find: The -delete action atomatically turns on -depth, but -prune 
      does nothing when -depth is in effect.  If you want to 
      carry on anyway, just explicitly use the -depth option.

Adding -depth disables the effect of -prune, which means .svn directories are also deleted. So: Which find syntax (if any) can be used to prune and then delete some of the non-pruned paths, without using other tools like rm?

share|improve this question
up vote 4 down vote accepted

You can use -path, it's not POSIX but supported by many implementations :

find . \! -path "*/.svn/*" -empty -delete

-regex is an option too.

share|improve this answer
I think all the implementations that have -delete also have -path. So this solution should work everywhere that's withing the scope of the question. – Gilles Aug 29 '11 at 21:00

If whitespace is not a problem, something like this will work

find . \( -name .svn -prune -false \) -o -print | tac | xargs -L rm -f

The advantage of this approach is that it's a big performance win when the parts of the tree we're avoiding with -prune are large. The downside is that -delete will delete things as soon as it sees a leaf, but this command has to wait until find exits. So if there is a lot of stuff to delete, but not much of the search space was pruned, it may not be a win.

share|improve this answer
Sorry, whitespace is always a problem. But maybe there's a way to use tac with a \0 separator? – l0b0 Jun 5 '12 at 18:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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