recursive cp that will only pick up certain extensions

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
zip184 [ Do, 20 Dezember 2007 21:19 ] [ ID #1891084 ]

Re: recursive cp that will only pick up certain extensions

On Dec 20, 3:19 pm, zip... [at] 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 \;
Lew Pitcher [ Do, 20 Dezember 2007 21:46 ] [ ID #1891085 ]

Re: recursive cp that will only pick up certain extensions

On 2007-12-20, zip184 [at] gmail.com <zip184 [at] 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 -;}
Bill Marcum [ Do, 20 Dezember 2007 21:58 ] [ ID #1891086 ]

Re: recursive cp that will only pick up certain extensions

On Thu, 20 Dec 2007 12:19:57 -0800 (PST), zip184 [at] 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
Stephane CHAZELAS [ Fr, 21 Dezember 2007 08:56 ] [ ID #1891894 ]

Re: recursive cp that will only pick up certain extensions

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

> On Thu, 20 Dec 2007 12:19:57 -0800 (PST), zip184 [at] 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
Icarus Sparry [ Fr, 21 Dezember 2007 10:00 ] [ ID #1891897 ]

Re: recursive cp that will only pick up certain extensions

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
Stephane CHAZELAS [ Fr, 21 Dezember 2007 10:48 ] [ ID #1891901 ]
Linux » comp.unix.shell » recursive cp that will only pick up certain extensions

Vorheriges Thema: Hex to decimal replacement
Nächstes Thema: killing another users process