Mailinglist Archive: opensuse (2831 mails)

< Previous Next >
Re: [SLE] Duplicating a directory structure
  • From: Darryl Gregorash <raven@xxxxxxxxxxxxx>
  • Date: Thu, 27 Jul 2006 15:49:27 -0600
  • Message-id: <44C934E7.5010002@xxxxxxxxxxxxx>
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@xxxxxxxx
Also check the archives at http://lists.suse.com
Please read the FAQs: suse-linux-e-faq@xxxxxxxx


< Previous Next >
References