Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you recursively copy all of the *.foo files in src to target using cp and/or find?

Tags:

find

copy

cp

cygwin

cp -v -ur path/to/jsps/ /dest/path/

The above command copies all of the files that have been updated from the source directory to the destination, preserving the directory structure.

What I can't figure out is how to copy only *.someExtention files. I know that you can use something like:

find -f -name *.jsp -exec some awesome commands {}

But I don't know how to do it (and I don't have time to read the info pages in detail).

All help is greatly appreciated.

Thanks, LES

like image 637
les2 Avatar asked Dec 08 '25 12:12

les2


2 Answers

If you want to use find / cp then the following should do the trick:

find -f -name *.jsp -exec cp --parents {} /dest/path \;

but rsync is probably the better tool.

like image 178
Eddie Avatar answered Dec 11 '25 17:12

Eddie


rsync might help - you can tell it to just copy certain files with a combination of include and exclude options, e.g.

rsync -a \
   --include='*.foo' \
   --include='*/' \
   --exclude='*' \
   path/to/jsps/ /dest/path/

See the manual and look at the section entitled FILTER RULES for more.

like image 40
Paul Dixon Avatar answered Dec 11 '25 17:12

Paul Dixon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!