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?
Asked
Active
Viewed 1,890 times
2
-
Which OS are you using? – quanta Mar 11 '13 at 11:50
-
@quanta It's Linux. – Anton Daneyko Mar 11 '13 at 11:52
3 Answers
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
--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