PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > recursive cp that will only pick up certain extensions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

recursive cp that will only pick up certain extensions

Réponse
 
LinkBack Outils de la discussion
Vieux 20/12/2007, 20h19   #1
zip184@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 20/12/2007, 20h46   #2
Lew Pitcher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: recursive cp that will only pick up certain extensions

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 \;

  Réponse avec citation
Vieux 20/12/2007, 20h58   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: recursive cp that will only pick up certain extensions

On 2007-12-20, zip184@gmail.com <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 -;}
  Réponse avec citation
Vieux 21/12/2007, 07h56   #4
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: recursive cp that will only pick up certain extensions

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
  Réponse avec citation
Vieux 21/12/2007, 09h00   #5
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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@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
  Réponse avec citation
Vieux 21/12/2007, 09h48   #6
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h58.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14608 seconds with 14 queries