How 7-Zip Handles Symbolic Links and Hard Links
When performing backup operations, 7-Zip's handling of symbolic links and hard links depends largely on the archive format selected, the underlying operating system, and the specific command-line parameters used. By default, 7-Zip may follow links and duplicate target data rather than preserving the link structures themselves. However, with dedicated switches, users can control whether 7-Zip archives links as pointers or dereferences them to back up the underlying target files.
Default Behavior
Without specific switches, the standard 7-Zip graphical interface and command-line tool often dereference symbolic links. This means 7-Zip treats the symlink as if it were the actual file or directory it points to, copying the full contents into the archive. For hard links, 7-Zip treats each instance as an independent file, which duplicates data across the archive and consumes unnecessary storage space.
Archiving Symbolic Links
(-snl)
To prevent dereferencing and ensure symbolic links are saved as
links, 7-Zip provides the -snl switch (Store symbolic links
as links).
- Behavior: When
-snlis enabled, 7-Zip records the link itself along with its target path, without traversing the link or copying the target file's contents. - Format Support: This is fully supported in native
.7zand.tarformats. - Cross-Platform Support: Works on both Windows (NTFS
symbolic links and junction points) and Unix-like operating systems
using modern ports (
7zzorp7zip).
Archiving Hard Links
(-snh)
Hard links point directly to the same inode or file record on a
storage volume. To preserve this relationship, 7-Zip offers the
-snh switch (Store hard links as links).
- Behavior: When
-snhis applied, 7-Zip identifies files that share the same data stream on the disk. It stores the file data once and marks subsequent references as hard links to the primary file. This drastically reduces backup size and maintains the original file structure upon extraction. - Format Support: Preserved natively within the
.7zformat and standard.tararchives.
Archive Format Compatibility
The choice of archive format is critical when backing up links:
- .7z: Supports both
-snland-snh. It accurately stores relative and absolute link targets along with link metadata. - .tar: Fully supports standard POSIX hard links and symbolic links natively.
- .zip: Has limited and inconsistent support for link preservation across different operating systems. It is not recommended for backups requiring strict link retention.
Restoration Considerations
Extracting backups that contain links requires appropriate system permissions:
- Windows: Creating symbolic links during extraction typically requires elevated administrator privileges or Windows Developer Mode enabled. If extracted without required permissions, 7-Zip may produce errors or skip link creation.
- Linux/macOS: Standard users can extract symbolic links, but creating hard links requires write access to the target filesystem and must reside on the same partition.