Copying a directory tree (was: xargs)

Marcel Grandemange thavinci at thavinci.za.net
Thu Aug 21 13:17:08 UTC 2008


Thank you all! And im on my way thanks to greate response!

-----Original Message-----
From: Oliver Fromme [mailto:olli at lurza.secnetix.de] 
Sent: Thursday, August 21, 2008 2:42 PM
To: freebsd-questions at FreeBSD.ORG; thavinci at thavinci.za.net
Subject: Copying a directory tree (was: xargs)

Marcel Grandemange <thavinci at thavinci.za.net> wrote:
 > I need to copy an entire BSD installation except
 > the /mnt directory to /mnt/pc

You don't need xargs for this.

# cd /
# find -Ed . -regex '\./(mnt|dev)' -prune -or -print0 | cpio -dump0 /mnt/pc

If you have procfs mounted, add "|proc" to the regex,
or simply umount it before.  It's not required for
anything important.

Or -- slightly less efficient, but this might be better
if you're more familiar with grep than with find:

# cd /
# find -d . | egrep --null -v '^\./(mnt|dev)/' | cpio -dump0 /mnt/pc

Yet another way is to use cpdup (from ports/sysutils/cpdup):

# echo mnt > .cpignore
# cpdup -x / /mnt/pc

Note that cpdup doesn't cross mountpoints, so you don't
have to exclude dev or proc.  But you will have to repeat
the command for /var, /usr, /tmp or any other directories
that are on separate file systems.

 > Ls | grep -v proc | xargs cp -Rpv /mnt/pc

Do not use cp -R or cp -r.  It has several problemsm,
for example it breaks hardlinks.  In my opinion the
-R and -r options of cp(1) should be removed, or a big
fat warning message should be printed, because they're
abused most of the time and cause breakage that other
people have to find and clean up afterwards.  Been
there, done that, a thousand times.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

Perl is worse than Python because people wanted it worse.
        -- Larry Wall

__________ NOD32 3372 (20080820) Information __________

This message was checked by NOD32 antivirus system.
http://www.eset.com




More information about the freebsd-questions mailing list