Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Which OS are you using? –  quanta Mar 11 '13 at 11:50
    
@quanta It's Linux. –  mezhaka Mar 11 '13 at 11:52

3 Answers 3

up vote 2 down vote accepted

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).

share|improve this answer

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

share|improve this answer
$ 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
share|improve this answer
    
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! –  Tonin Mar 11 '13 at 17:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.