3

I have quite complex directory tree. There are many subdirectories, in those subdirectories beside other files and directories are ".svn" directories.

Now, under linux I want to delete all files and directories except the .svn directories.

I found many solutions about opposite behaviour - deleting all .svn directories in the tree. Can somebody quote me the correct answer for deleting everything except .svn?

Arek
  • 255

3 Answers3

7

I usually use a relatively simple find with the -exec option, as I always forget about the -delete command. I also restrict to files-only. Mostly because I use some variation of find {someswitches} -exec {somecommand} a lot - so I remember it!

find . -type f -not path '*.svn*' -exec rm {} \;

Cylindric
  • 1,097
1

Untested: find . -not -path '*.svn*'... if those are all the files you want to clobber, run it again with the -delete option.

medina
  • 1,965
0

Try this rm -rf -- $(ls -la |grep -v .svn). It will remove everything (including hidden files) except the .svn dir.

EDIT: The above solution works for one dir, not a tree, find . ! -name .svn -exec rm {} \; will remove all FILES and not the dirs. It's a safe way to do that, since if you force the rm on directories you can delete directories that have .svn directories inside.

coredump
  • 12,921