[SLE] Duplicating a directory structure
I need to duplicate a directory structure on a SuSE 10.0 box -- not the files, just the directory tree. I thought this would be pretty simple, using find, but I'm running into big issues because many (as in almost all) of the directories have spaces in their names. For the life of me I can't get the silly thing to put everything where it should be. The current directory structure is something like the following: /tmp/origin /tmp/origin/folder one /tmp/origin/folder one/sub folder one /tmp/origin/folder one/sub folder two /tmp/origin/folder one/sub folder three /tmp/origin/folder one/sub folder three/sub sub folder one /tmp/origin/folder one/sub folder three/sub sub folder two /tmp/origin/folder one/sub folder four /tmp/origin/folder two /tmp/origin/folder two/sub folder one . . . (Suffice it to say that the actual structure is much more complicated, and, well, real. But not essentially different.) What I'm trying to end up with is something like this: /tmp/dest /tmp/dest/folder one /tmp/dest/folder one/sub folder one /tmp/dest/folder one/sub folder two /tmp/dest/folder one/sub folder three /tmp/dest/folder one/sub folder three/sub sub folder one . . . I started off by doing this: `cd /tmp/origin` `find . -type d -print | xargs mkdir {}` which gave me lots of errors like "mkdir folder: file exists" and "mkdir one/sub: file exists". Clearly "folder" and "one/sub" are being seen as distinct file names. Anyone have any thoughts/advice on what I can do to duplicate the structure? I know it's really just a question of quoting/escaping the output of the find command, but for the life of me I can't figure out where to put the quotes! Thanks... - IAn -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
I need to duplicate a directory structure on a SuSE 10.0 box -- not the files, just the directory tree.
I thought this would be pretty simple, using find, but I'm running into big issues because many (as in almost all) of the directories have spaces in their names. For the life of me I can't get the silly thing to put everything where it should be.
The current directory structure is something like the following: /tmp/origin /tmp/origin/folder one Use the cp(1) command with the -r (recursive) option. Note that -p also
On Thursday 27 July 2006 2:11 pm, Marlier, Ian wrote: preserves permissions. Alternatively, rsync or even tar: cd /tmp mkdir /tmpdup tar cf - . | (cd /tmpdup;tar xf -) -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9 -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
On 27/07/06 12:11, Marlier, Ian wrote:
I need to duplicate a directory structure on a SuSE 10.0 box -- not the files, just the directory tree.
<snip>
I started off by doing this: `cd /tmp/origin` `find . -type d -print | xargs mkdir {}`
I think you probably wanted to be in /tmp/dest here, but the result is still the same: mkdir always tries to recreate the original directory. Greg Freemyer mentioned the -print0 and -0 options to find and xargs, respectively. (Actually, the only reason I don't get the credit is because Mozilla crashed on me *&(*(&^&%*&^(&)*(*_)*&*^% as soon as I hit the "send" button, but I am not complaining... errr, ummm.. ) Greg suggests an innovative approach, but while I was mucking about with find and xargs, I found another solution, which I think is actually much simpler. The find command has a -exec option which does exactly what the xargs pipe does. Try this: cd /tmp/origin find . -type d -exec mkdir -p '../dest/{}' \; "mkdir -p" will create any necessary parents (in this case, /tmp/dest). The semi-colon does need to be escaped, and the single quotes are probably necessary, to prevent shell interpretation of the {} (which stands for "the current file" in find). -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
On Thursday 27 July 2006 20:11, Marlier, Ian wrote:
The current directory structure is something like the following: /tmp/origin ... `cd /tmp/origin` `find . -type d -print | xargs mkdir {}`
One way is this: tar cf /tmp/foo.tar --no-recursion $(find . -type d) Now foo.tar contains the structure. Simply unpack it to your destination. If you're clever you can find a way to expand that to not use a temp tar file, but we'll leave that as an exercise for the reader :). -- ----- stephan@s11n.net http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts
Marlier, Ian wrote:
I need to duplicate a directory structure on a SuSE 10.0 box -- not the files, just the directory tree.
I thought this would be pretty simple, using find, but I'm running into big issues because many (as in almost all) of the directories have spaces in their names. For the life of me I can't get the silly thing to put everything where it should be.
The current directory structure is something like the following: /tmp/origin /tmp/origin/folder one /tmp/origin/folder one/sub folder one /tmp/origin/folder one/sub folder two /tmp/origin/folder one/sub folder three /tmp/origin/folder one/sub folder three/sub sub folder one /tmp/origin/folder one/sub folder three/sub sub folder two /tmp/origin/folder one/sub folder four /tmp/origin/folder two /tmp/origin/folder two/sub folder one . . .
(Suffice it to say that the actual structure is much more complicated, and, well, real. But not essentially different.)
What I'm trying to end up with is something like this: /tmp/dest /tmp/dest/folder one /tmp/dest/folder one/sub folder one /tmp/dest/folder one/sub folder two /tmp/dest/folder one/sub folder three /tmp/dest/folder one/sub folder three/sub sub folder one . . .
I started off by doing this: `cd /tmp/origin` `find . -type d -print | xargs mkdir {}`
which gave me lots of errors like "mkdir folder: file exists" and "mkdir one/sub: file exists". Clearly "folder" and "one/sub" are being seen as distinct file names.
Try this (assuming /tmp/dest/ exists): cd /tmp/dest (cd /tmp/origin; find -type d -print0) | xargs -0 mkdir -p -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
participants (5)
-
Darryl Gregorash
-
Jerry Feldman
-
M. Nejat AYDIN
-
Marlier, Ian
-
stephan beal