Home » Questions » Computers [ Ask a new question ]

Copy all files and folders excluding subversion files and folders on OS X

Copy all files and folders excluding subversion files and folders on OS X

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.

Asked by: Guest | Views: 41
Total answers/comments: 5
Guest [Entry]

"(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:

find ./sourcedirectory -not ( -name .svn -a -prune ) -print0 | xargs -0 -IFILES cp FILES ./destinationdirectory

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 is a useful shorthand for
excluding a broad range of files that
you often don't want to transfer
between systems. It uses a similar
algorithm to CVS to determine if a
file should be ignored.

This will tell rsync to ignore these patterns:

RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo *~
#* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj
*.so *.exe *.Z *.elc *.ln core .svn/ .git/ .bzr/

For example:

rsync -avC /path/to/source/directory /path/to/destination/directory

(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')"
Guest [Entry]

"%> mkdir -p FOLDER_OUT && ( tar cf - FOLDER_OR_FILES_IN --exclude=.svn | tar xvf - -C FOLDER_OUT )

if you want you can even put 'pv' or something similar in between the 2 tar processes."
Guest [Entry]

"Edited answer: The problem is that -R makes your copying recursive and so you end up copying the hidden files. Here is what I would use:

find source/ -mindepth 1 -not \( -name .svn -prune \) | xargs -Iitem cp item target/

The -mindepth 1 flag tells find to ignore the toplevel directory. Since you want to copy all of the content of that directory into a new toplevel directory, I assume you don't want that.

As Chris Nava says in his answer, there's already a built-in way to do this if we're talking about SVN folders, but since you asked for a more general solution, this may help a bit."
Guest [Entry]

"I suppose it depends how big your tree is, but why not just copy everything first, then trim the .svn folders after:

find /dest-dir -type d -name .svn -exec rm -rf {} \;

Guest [Entry]

"Don't forget grep -v

find . | grep -v .svn"