0

I have a directory tree under ./src/

I have another matching directory tree under ./work/

I'm trying to copy all the files in src to work, while keeping the directory structure and excluding all files that end in .java.

Here's my attempt so far:

find src -type f ! -iname *.java -exec cp {} work \;

This almost works, but all the files are put into the top level under work, instead of into the correct place in the directory tree.

How can I do this? (using bash on Mac OS X 10.9)

Steve McLeod
  • 190
  • 1
  • 1
  • 10

3 Answers3

3

tar cCf /source/path - --exclude "*.java" . | tar xCf /target/path -

Chris S
  • 77,945
  • 11
  • 124
  • 216
0
rsync -a --exclude='*.java' src/ work/
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
-1

You can use {} multiple times. So:

find src -type f ! -iname '*.java' -exec cp {} work/{} \;

will try and preserve path (and fail, because the directory probably doesn't exist. - however you could probably do:

-exec mkdir -p `dirname {}` \;

However, for what you're doing, you probably want to use tar:

find src -type f ! -iname '*.java' | xargs tar cvf - | ( cd work && tar xvf - )
Sobrique
  • 3,747
  • 2
  • 15
  • 36