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
Best Answer
(Edited after re-reading the question. Questioner says rsync is not installed)
A possible problem with your find/xargs solution is spaces in the filenames. To get around that, tell find and xargs to use a null character (ASCII 0) to separate the found files:
If you find that rsync is available, I still think that rsync is the far better solution:
Use rsync with the -C option. From the rsync man page:
This will tell rsync to ignore these patterns:
For example:
(note: If you're not too familiar with rsync yet, be sure to read on that man page about how rsync deals with a trailing slash in the source path. It behaves differently if you include the slash than if you don't. Search for 'trailing slash')