Mac Unix copy directory but skip files

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
3
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.
 

lexfuzo

macrumors 6502
Mar 15, 2005
262
0
The heart of Europe
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

...
 

balamw

Moderator
Staff member
Aug 16, 2005
19,360
963
New England
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
 

savar

macrumors 68000
Jun 6, 2003
1,952
0
District of Columbia
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
 

kainjow

Moderator emeritus
Original poster
Jun 15, 2000
7,958
3
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 {} \;
 

mrkenzie

macrumors newbie
Nov 24, 2006
1
0
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.
 

balamw

Moderator
Staff member
Aug 16, 2005
19,360
963
New England
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