Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
- To: "MLUG Members" <EMAIL:PROTECTED>
- Subject: RE: [MLUG] copying many trees together
- From: "McNutt, Justin M." <EMAIL:PROTECTED>
- Date: Wed, 5 Sep 2007 11:31:04 -0500
- Delivery-date: Wed, 05 Sep 2007 11:31:45 -0500
- Envelope-to: EMAIL:PROTECTED
- In-reply-to: <EMAIL:PROTECTED>
- Reply-to: MLUG Members <EMAIL:PROTECTED>
- Sender: EMAIL:PROTECTED
- Thread-index: AcfvdhIANZTsikDgSJOidWEeOsZjGwAYWe6Q
- Thread-topic: [MLUG] copying many trees together
> Mike Miller wrote:
> > Suppose I have a bunch of directory trees like these and
> there may be
> > files in any all of the directories:
> >
> > A-- foo
> > `-- bar
> >
> >
> > B-- foo
> > `-- bar
> > `-- billy
> > `-- willy
> >
> >
> > C-- foo
> > `-- bar
> > `-- billy
> > `-- sue
> >
> >
> > D-- foo
> > `-- bar
> > `-- sally
> > `-- joe
> >
> >
> > E-- foo
> > `-- baz
> > `-- fun
> > `-- stuff
> >
> >
> > F-- foo
> > `-- baz
> > `-- unfun
> > `-- stuff
> >
> > I want to put all of those directories, with the files into a single
> > tree like so:
> >
> > X-- foo
> > |-- bar
> > | |-- billy
> > | | |-- sue
> > | | `-- willy
> > | `-- sally
> > | `-- joe
> > `-- baz
> > |-- fun
> > | `-- stuff
> > `-- unfun
> > `-- stuff
> >
> > This could be done in succession with files from A copied first,
then B,
> > then C, etc., and it would be fine to overwrite files because files
with
> > the same name in the same position in the tree are always identical.
> >
> > What's the best way to do this? Is there anything made for this?
Does
> > rsync do this kind of thing? I wish cp could do it but I don't see
an
> > option for it.
Interesting. If I were doing it only once, I would do:
mkdir X;
cd A; cp -r -- . /path/to/X/
cd B; cp -r -- . /path/to/X/
...etc.
The advantage of "cp -r --" is that the same syntax works using "scp -r
-- <src> <dst>". Only cp and scp require the "--" to prevent weird file
names from screwing up operations. Tar and rsync (below) operate on
directories.
Tar can do the same thing, though the syntax is more evil. The upside
is that tar (or rsync) will preserve timestamps, ownership, and
permissions (if run as a user with sufficient privs to do so):
mkdir X;
cd A; tar -cvf - . | tar -xvf - -C /path/to/X
cd B; tar -cvf - . | tar -xvf - -C /path/to/X
...etc.
Or rsync:
mkdir X;
cd A; rsync -ax . /path/to/X
cd B; rsync -ax . /path/to/X
...etc.
Do NOT use the "--delete" option or you won't get a "merge". You'll
just get a copy of the last directory rsync'd.
Whatever method you use, all of the above don't care about the source
location except in the "cd" part, so it ought to be easily scriptable.
I would do it as a perl job: foreach my $dir ( ('A', 'B', 'C'...) ) { #
do foo } Others have already posted similar bash scripted code.
NOTE: If you do it as a script, it might actually be easier to set up
your script to copy only ONE specified directory from $ARGV[0] to X.
Then you can use 'find':
find . -type d -maxdepth 1 -exec ./CopyToX {} \;
You don't need a script "CopyToX" for the 'cp', 'scp', or 'rsync'
commands, but you need the script if you use 'tar', because the copy
method includes a pipe, which will screw up the 'find' command. In all
cases, using a script is also a lot more flexible. Lastly, the 'find'
command won't work very well if you want to copy ./[A-F]/ -> X/, but
there are other things in that directory - like [G-Z]/ - that you DON'T
want to copy. At that point, you're back to a hard-coded list, since
it's probably less work than hacking 'find' to just match what you want.
DON'T just do 'find . -mindepth 2 -maxdepth 2 -exec cp -r -- {} X/ \;'.
That won't do what you expect. Instead of:
X/foo/stuff
X/bar/stuff (merged A-F)
You'll get:
X/A/foo/stuff
X/B/foo/stuff
X/A/bar/stuff
X/B/bar/stuff
If you want that, you could just use "cp -r -- [A-F] X/" (or 'mv') and
be done.
--J
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members