recursive cp that will only pick up certain extensions

recursive cp that will only pick up certain extensions

am 20.12.2007 21:19:57 von zip184

I'm writing a shell script that needs to copy files with a certain
extension out of a large directory structure. Is there a single
command that can do this? I tried many combinations of find, cp -r,
exec, piping. Nothing I can think of works, but I am an armature at
best. I'm using cygwin. Can anyone show me a single command that can
do this? I want to avoid writing a recursive script or something of
that nature. -Thanks

Ex. cp -r ( copy only *.pbl ) newdir

Re: recursive cp that will only pick up certain extensions

am 20.12.2007 21:46:55 von Lew Pitcher

On Dec 20, 3:19 pm, zip...@gmail.com wrote:
> I'm writing a shell script that needs to copy files with a certain
> extension out of a large directory structure. Is there a single
> command that can do this? I tried many combinations of find, cp -r,
> exec, piping. Nothing I can think of works, but I am an armature at
> best. I'm using cygwin. Can anyone show me a single command that can
> do this? I want to avoid writing a recursive script or something of
> that nature. -Thanks
>
> Ex. cp -r ( copy only *.pbl ) newdir

find . -name '*.pbl' -exec cp {} newdir \;

Re: recursive cp that will only pick up certain extensions

am 20.12.2007 21:58:02 von Bill Marcum

On 2007-12-20, zip184@gmail.com wrote:
>
>
> I'm writing a shell script that needs to copy files with a certain
> extension out of a large directory structure. Is there a single
> command that can do this? I tried many combinations of find, cp -r,
> exec, piping. Nothing I can think of works, but I am an armature at
> best. I'm using cygwin. Can anyone show me a single command that can
> do this? I want to avoid writing a recursive script or something of
> that nature. -Thanks
>
> Ex. cp -r ( copy only *.pbl ) newdir

tar cf - $( find . -name '*.pbl' ) | {cd newdir; tar xf -;}

Re: recursive cp that will only pick up certain extensions

am 21.12.2007 08:56:47 von Stephane CHAZELAS

On Thu, 20 Dec 2007 12:19:57 -0800 (PST), zip184@gmail.com wrote:
> I'm writing a shell script that needs to copy files with a certain
> extension out of a large directory structure. Is there a single
> command that can do this? I tried many combinations of find, cp -r,
> exec, piping. Nothing I can think of works, but I am an armature at
> best. I'm using cygwin. Can anyone show me a single command that can
> do this? I want to avoid writing a recursive script or something of
> that nature. -Thanks
>
> Ex. cp -r ( copy only *.pbl ) newdir

cd olddir && find . -name '*.pbl' -print | pax -rwdpe ../newdir

pax will create directories in ../newdir as needed but not
necessarily with the same permissions and owners as they were in
olddir.

Note that the above assumes that no file name contains any
newline character.

--
Stephane

Re: recursive cp that will only pick up certain extensions

am 21.12.2007 10:00:17 von Icarus Sparry

On Fri, 21 Dec 2007 07:56:47 +0000, Stephane Chazelas wrote:

> On Thu, 20 Dec 2007 12:19:57 -0800 (PST), zip184@gmail.com wrote:
>> I'm writing a shell script that needs to copy files with a certain
>> extension out of a large directory structure. Is there a single
>> command that can do this? I tried many combinations of find, cp -r,
>> exec, piping. Nothing I can think of works, but I am an armature at
>> best. I'm using cygwin. Can anyone show me a single command that can
>> do this? I want to avoid writing a recursive script or something of
>> that nature. -Thanks
>>
>> Ex. cp -r ( copy only *.pbl ) newdir
>
> cd olddir && find . -name '*.pbl' -print | pax -rwdpe ../newdir
>
> pax will create directories in ../newdir as needed but not necessarily
> with the same permissions and owners as they were in olddir.
>
> Note that the above assumes that no file name contains any newline
> character.

This is parsed as
cd olddir && { find ... | pax ... }
which is probably not what you want, in particular if "newdir" is
something like ~- or an absolute path.

Better to use a subshell

( cd olddir && find ... ) | pax -rwdpe newdir

Re: recursive cp that will only pick up certain extensions

am 21.12.2007 10:48:26 von Stephane CHAZELAS

On 21 Dec 2007 09:00:17 GMT, Icarus Sparry wrote:
[...]
>> cd olddir && find . -name '*.pbl' -print | pax -rwdpe ../newdir
>>
>> pax will create directories in ../newdir as needed but not necessarily
>> with the same permissions and owners as they were in olddir.
>>
>> Note that the above assumes that no file name contains any newline
>> character.
>
> This is parsed as
> cd olddir && { find ... | pax ... }
> which is probably not what you want, in particular if "newdir" is
> something like ~- or an absolute path.
>
> Better to use a subshell
>
> ( cd olddir && find ... ) | pax -rwdpe newdir

No, the paths output by find must be accessible by pax, so pax'
current directory must be the same as find's which wouldn't be
the case in the syntax you suggest.

Note my use of "../newdir" above. That assumes "oldir" and
"newdir" are subdirectories of a same directory.

--
Stephane