Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.