How 7-Zip Handles Duplicate Files in Compression

When compressing data, 7-Zip processes duplicate files differently depending on whether they share identical content under different filenames or identical filenames during an archive update. Through its native solid compression feature, 7-Zip efficiently deduplicates redundant data blocks across identical files to minimize archive size, while using update policies and overwrite prompts to resolve filename collisions.

Identical File Content (Different Names)

Operating systems do not permit two files with the exact same name in the same directory. Therefore, duplicate files inside a single folder exist as distinct filenames containing identical byte streams (for example, report.pdf and report_copy.pdf).

When compressing these files into the native .7z format, 7-Zip handles the duplicate content through Solid Compression:

  • Continuous Data Stream: In solid mode (enabled by default in .7z), 7-Zip treats multiple files as a single, uninterrupted stream of data.
  • Dictionary Matching: The compression algorithm (typically LZMA or LZMA2) uses a sliding dictionary window to detect repeated sequences of data. When it encounters the second duplicate file, the algorithm references the identical byte sequence from the first file rather than compressing the duplicate data again.
  • Storage Impact: The compressed archive stores the file metadata (names, timestamps, and attributes) for both files, but the actual file content is stored only once. Consequently, duplicate files add virtually zero additional size to the compressed archive beyond a few bytes of metadata.
  • Non-Solid Archives (Standard ZIP): If you compress using the standard .zip format or manually disable solid compression in .7z, 7-Zip compresses each file individually. In this scenario, duplicate files are compressed independently, and no deduplication occurs.

Identical Filenames During Archive Updates

If you add files to an existing 7-Zip archive and a file with the same name already exists in the target directory within the archive, 7-Zip treats this as a conflict:

  • Graphical Interface (GUI): A prompt appears asking how to resolve the collision. Options include replacing the file, updating it only if the incoming file is newer, skipping the file, or auto-renaming the incoming file.
  • Command Line Interface (CLI): 7-Zip provides the -ao (Overwrite mode) switch to dictate handling without prompting:
    • -aoa: Overwrites all existing destination files.
    • -aos: Skips extracting or compressing files that already exist.
    • -aou: Auto-renames the incoming file (e.g., adding a numerical suffix).
    • -aot: Auto-renames the existing file before writing the new one.
  • Update Commands (-u): Advanced users can use the -u switch to define state actions based on whether the file exists only in the archive, only on the disk, or in both locations with differing timestamps.