copy and create parent dirs
Dear LQ,
Say you want to copy /usr/share/zoneinfo inside of another directory (a jail, for context, but that's irrelevant), say /var/www/clients/client1/web5/, but you want to create all the parents of zoneinfo inside that destination directory, so you'd end up having the contents inside /var/www/clients/client1/web5/usr/share/zoneinfo, all the parent directories have to be created. Is there a way to achieve this in one command ? (cp or rsync with some options maybe ?) I know you can always do a mkdir -p /var/www/clients/client1/web5/usr/share/zoneinfo beforehand but I was just curious to know if this can be achieved otherwise by a relevant copy command |
Hi,
I'd say I either am misreading, or I do not understand what you wish to do. To me why isn't "cp -R" satisfactory? I mean there are switches to preserve, copy, whatever any sym links. I think it's either --preserve or -p or -P, have to look it up, plus also there's a -a option. I do recall having a situation (script) which copied a tree onto a new disk where I was establishing the disk otherwise and dd just wouldn't do it for me at the time, so I used a "cp -a" form. I mean, ... you seem to want to copy a directory tree. Is that not what things like cp and rsync do for you? Or have you not explored staging this as yet? |
dear rtmistler,
cp -R/-r /tmp/foo/bar/baz /tmp2/ will copy the baz directory directly under /tmp2/. I want to copy it inside /tmp2/foo/bar/, without creating /tmp2/foo/bar myself -the command should do it for me- I haven't found any option for cp that do that (even --parents, which only seems to work for a single file, not for a whole directory). But it seems rsync has a nice --relative option that will create the necessary parent directory to match those of the source directory. I might as well mark this thread as solved, but other solutions are welcome :) |
Do you want to merge two existing & identical (or, let's say, compatible) directory structures with all files that are in it?
|
I wouldn't say "merge". I like how rtmistler uses the term "directory tree" or directory structure. If I say merge then that would imply the directory structure already exists on both paths, which is not the case (only exists in the source, but hasn't been created on the destination yet).
|
I usually do a "tar | tar"
Code:
( cd / && tar cf - usr/share/zoneinfo ) | ( cd /var/www/clients/client1/web5 && tar xf - ) For example, if I want to skip the /usr then I do Code:
( cd /usr && tar cf - share/zoneinfo ) | ( cd /var/www/clients/client1/web5 && tar xf - ) |
Quote:
Unless the target is supposed to be really deeply nested, a single "mkdir -p /subdir1/subdir2/subdir3/..." should be all that's needed to create the other directories, no? What about something like: Code:
TGT=/top-level/subdir1/subdir2/subdir3/destdir Code:
$ TGT=`pwd` Code:
$ TGT=`pwd` Have a good one... |
All times are GMT -5. The time now is 10:16 AM. |