|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 \; |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 -;} |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|