1

If we have a file on a disk and create a hard link pointing to it then we have two references to the same data. If one link gets deleted it does not affect the other link as it is directly pointing to the data.

If I have two links (A and B) pointing to file ABC and I move link A to another disk then I will have two copies of the data. Link A will be pointing to the data on the new disk and link B pointing to the data on the old disk.

If I want to move both links A and B to a new disk how can I do this without end up having two copies of data on the new disk?

  • Sounds like you are not completely clear on the concept of hard-links; it can be a challenge until you are comfortable with the idea. – 0xSheepdog Apr 18 at 14:36
1

rsync is able to copy hard links for you. Check -H option:

-H, --hard-links            preserve hard links
  • Perfect. Just what I was looking for. Thank you. – Pusdeo Squirrel Apr 18 at 15:14
-1

What you describe is actually THREE (3) pointers to the data on the disk:

  • ABC
  • A
  • B

If you mv A onto a new filesystem, it essentially creates a copy of the data on the new filesystem.

If you mv B onto the new filesystem, it creates another copy of the data named B on the new filesystem. But, ABC is left on the original filesystem still.

What you should do, if you want to replicate the original file and links on the new filesystem (replace source/ and new-file-system/ with your correct paths):

  1. cp source/ABC new-file-system/ABC
  2. ln new-file-system/ABC A
  3. ln new-file-system/ABC B
  4. rm source/ABC source/A source/B

This will copy/create the data on the new file system, create the hard-links A and B on the new file system, then remove the old data and hard-links.

Please be sure to double check all syntax before you complete a command so you don't lose data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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