tags:

views:

85

answers:

2

I have a script that is copying a folder that contains a couple sub folders. The original that it is copying from is part of an SVN folder, so it is copying those ".svn" folders as well.

I want to remove those from the new destination, my best guess was:

rm -Rf dir/*.svn

Which doesn't work, is there a way to do this or do I need to manually go into each folder to delete it?

+1  A: 

Take a look at this: http://snippets.dzone.com/posts/show/2486

Matthew J Morrison
+5  A: 

From within the folder whose contents you want to filter:

find . -name '.svn' -print0 | xargs -0 rm -rf

or

find . -name '.svn' -exec rm -rf {} \;

Wevah
(The `-print0`/`-0` combo is in case your paths have any whitespace in them.)
Wevah
Worked like a charm, thanks!
Kerry
If I wanted that to also be another directory (such as DW's _notes) would that be a separate command or could that get added into this one?
Kerry
`find . -name '.svn' -o -name '_notes' -print0 | xargs -0 rm -rf`Name is .svn OR name is _notes
Stephen P
You could also do it with one of the regex flags, but Stephen's answer (+1'd) is easier (particularly if you're not awesome with regexes).
Wevah
You could also avoid copying the .svn directories in the first place, so they don't have to be removed. Check `man rsync` and the `--exclude=` option. (Note rsync can be used for local-to-local copies, it doesn't *have* to be remote)
Stephen P
I know regex pretty well, but have no idea how to use in shell (don't know any of the flags)
Kerry