14
5
I'm trying to copy all files and folders from one directory to another, but exclude certain files. Specifically, I want to exclude subversion files and folders. However, I'd like a general yet concise solution.
I imagine I'll find the need to exclude several types of files in the near future. For example, I might want to exclude .svn, *.bak, and *.prj.
Here is what I've put together so for, but it is not working for me. The first part, find works, but I'm doing something wrong with xargs and cp. I tried cp with and without the -R
. Also, I'm using OS X and it appears to have a less featured version of xargs than linux systems.
find ./sourcedirectory -not \( -name .svn -a -prune \)
| xargs -IFILES cp -R FILES ./destinationdirectory
I may be wrong, but I think that this is trickier than you think. Even if your
find
command properly uses-prune
to exclude .svn items, you then pass the-R
flag tocp
which tells that command to be recursive. When it does so, you lose whatever granularity you had in thefind
command. I'm going to tinker with this for a minute, but I think the answer is not to use-R
in thecp
command. – Telemachus – 2009-09-28T14:34:35.100It seems to work for me on a Linux system. Can you be more specific as to what "it is not working" means? Any error messages? Files getting/not getting copied that you expect? – Paused until further notice. – 2009-09-28T15:03:17.890
It's the
-R
flag, I'm pretty sure. Remove that and you should be fine (though you might want to add-mindepth 1
to ignore the toplevel directory folder which you don't want to copy, I assume) – Telemachus – 2009-09-28T15:22:42.227I usually do these things by copying everything, and then deleting the unwanted files in the target directories. That's often much simpler. – Jan Doggen – 2014-05-19T19:52:45.087