Store Symlinks as Links in 7-Zip CLI

When archiving files using the 7-Zip Command Line Interface (CLI), the utility defaults to copying the data of target files rather than preserving symbolic links. This guide explains how to use the -snl switch to preserve symbolic links as actual links within your archives, avoiding redundant file duplication and maintaining your original directory structure.

The Switch: -snl

The command-line switch used to store symbolic links as links is -snl.

By default, 7-Zip dereferences symlinks during archive creation. This means it follows the path of the link, reads the destination file or directory, and stores the full contents of that target inside the archive. Applying the -snl (Store symbolic Links) switch instructs the archiver to capture only the link metadata and its target path instead of the actual data.

Basic Syntax and Examples

To create an archive while preserving symbolic links, include -snl in your standard creation command:

7z a -snl archive.7z /path/to/source

In this command:

  • a tells 7-Zip to add files to an archive.
  • -snl enforces storing symbolic links as links.
  • archive.7z is the target output archive.
  • /path/to/source represents the files or directories being archived.

Updating or Adding to Archives

The switch can also be used during update operations:

7z u -snl archive.7z /path/to/source

Important Considerations

  • Archive Formats: Storing symlinks is fully supported in .7z and .tar formats. When saving to formats that lack symbolic link specifications (such as basic .zip without extended attributes depending on the platform), the links may not be preserved as intended.
  • Extraction Rights: On Windows, extracting archives that contain symbolic links generally requires elevated privileges (Run as Administrator) or having Developer Mode enabled, as standard Windows user accounts are restricted from creating symlinks by default. On Linux and macOS systems, this restriction typically does not apply.
  • Hard Links: The -snl switch applies strictly to symbolic links. If your workflow also includes hard links that you want stored as references rather than duplicates, you must use the -snh switch alongside -snl.