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?
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 offind {someswitches} -exec {somecommand}
a lot - so I remember it!find . -type f -not path '*.svn*' -exec rm {} \;
Untested:
find . -not -path '*.svn*'
... if those are all the files you want to clobber, run it again with the-delete
option.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 therm
on directories you can delete directories that have.svn
directories inside.