Modulok wrote:
What is the easiest way to copy a directory tree as hard links?

Linux has a nice little 'cp -al' flag combo to do this. The FreeBSD
cp(1) manual page says to use pax or tar, but how do I get the ability
to rename the file without first creating a destination file? I don't
want an archive, just regular directory tree sitting right next to the
original, but with a new name ... consisting of of hard links back to
the original. For example on linux I could do something like:

$ ls
foo/

$ cp -al foo bar

The result would be a new copy of foo, which takes up no additional
space, as all files share the same inodes. Is there an easy way to do
this on FreeBSD?

cpio(1)

Unfortunately the man page is pretty useless, and you have to hunt through
the info page instead.  But something like this should do what you want:

   # cd /some/dir
   # find . -depth -type f -print0 | cpio -0pdl /other/dir

It's the 'l' (link) option that achieves the desired effect. Note: this should
link only files but it will create a parallel structure of sub-directories, so
it will use up a bit of space.

Actually, now I peruse the man page, pax(1) has very similar functionality,
and you could do something like this:

   # pax -rwl /some/dir /other/dir

You might also consider using nullfs mounts. In /etc/fstab:

   /some/dir /other/dir nullfs rw 0 0

See mount_nullfs(8).

        Cheers,

        Matthew
--
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                 Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                 Kent, CT11 9PW

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to