6

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?

4

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

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

-regex is an option too.

  • 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
0

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.

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