How to use rsync with hard link preservation to save disk space?

Published on Aug. 22, 2023, 12:18 p.m.

To use rsync with hard link preservation to save disk space, you can use the -H or --hard-links option to preserve hard links when copying files between directories. This will ensure that only one copy of the data is stored on disk, even if it appears in multiple directories.

Here is an example command to copy a directory with hard links preserved using rsync:

rsync -avzH /path/to/source/ /path/to/destination/

Explanation of the options used:

  • -a: archive mode, which preserves permissions, ownership, timestamps, and recursive copying
  • -v: verbose output
  • -z: compress file data during transfer to reduce bandwidth usage
  • -H: preserve hard links during transfer

Note that you should specify the trailing slash on the source and destination directories to ensure that the entire directory structure is preserved.

Tags: