Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
7
Anyone know of a unix command to copy a directory, but skip certain files? Kind of like the -x argument for zip. I looked at man cp and man ditto but didn't see any such option. Basically I'm writing a Bash script that automates copying a directory out of a Subversion repository, and I want to strip all the *.svn* files from it.
 
rsync

$ man rsync | grep exclude
o exclude and exclude-from options similar to GNU tar
o a CVS exclude mode for ignoring the same files that CVS would
rsync -avuzb --exclude ’*~’ samba:samba/ .
--delete-excluded also delete excluded files on receiver
-C, --cvs-exclude auto-ignore files in the same way CVS does
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don’t exclude files matching PATTERN

...
 
find would also be pretty easy to make this work.

something like cp `find . -not -name "*.svn"` destination/ (not tested)

You could add in xargs if there are lots of files in the source directory...

B
 
kainjow said:
Anyone know of a unix command to copy a directory, but skip certain files? Kind of like the -x argument for zip. I looked at man cp and man ditto but didn't see any such option. Basically I'm writing a Bash script that automates copying a directory out of a Subversion repository, and I want to strip all the *.svn* files from it.

find ./ -type d | xargs -i cp {} dest_dir

What do I win?

Oh wait, you only want to skip *some* files, not all of them. Okay:

find ./ ! -name '*.svn' | xargs -i cp {} dest_dir
 
Thanks guys, plenty of solutions.

I ended up just removing the files after I copied them, because I'm lazy :p

Code:
find directory -name "*.svn*" -exec rm -rf {} \;
 
I too am trying to copy files over and exclude certain files/directories. When I use the following code:

Code:
find ./ ! -name '*.svn' | xargs -i cp {} dest_dir

it works except if it needs to copy a new empty directory. So basically I am trying to synchronize to directories and it is working except for the case where there is an empty directory.

Anyone know how to get it to work including with empty directories?

Thanks.
 
I too am trying to copy files over and exclude certain files/directories. When I use the following code:

Code:
find ./ ! -name '*.svn' | xargs -i cp {} dest_dir

it works except if it needs to copy a new empty directory. So basically I am trying to synchronize to directories and it is working except for the case where there is an empty directory.

Anyone know how to get it to work including with empty directories?

Thanks.
I think it's a limitation of cp. You could try and just do it in two steps. Copy the directory structure with a
Code:
find ./ -type d ... |mkdir
first?

Or, use a tool better suited towards syncing, like rsync.

B
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.