2

I have a directory with huge files and a number of directories, that have hardlinks on these huge files. How do I copy files from one filesystem to the other and preserve hard links?

quanta
  • 51,413
  • 19
  • 159
  • 217

3 Answers3

4

rsync can preserve hard-links with the -H option.

Stone
  • 7,011
  • 1
  • 21
  • 33
2

tar is preserving links (both symbolic and hard ones). To copy between filesystems, you would use it that way:

tar -cf - -C srcdir . | tar -xpf - -C destdir

See the tar man page for more details (this is where this example is actually coming from).

Lætitia
  • 2,085
  • 22
  • 33
1
$ cp -r --preserve=links src dst

man cp:

   --preserve[=ATTR_LIST]
          preserve  the specified attributes (default: mode,ownership,timestamps), 
          if possible additional attributes: context, links, xattr, all
quanta
  • 51,413
  • 19
  • 159
  • 217
  • From the man page, it is not very clear that `cp` invoked that way preserves both symbolics and hard links. But after some testing, that seems to work, interesting! – Lætitia Mar 11 '13 at 17:07