Preserve File Modification Times in 7-Zip

This article explains how to preserve original file modification times when creating and extracting archives using the 7-Zip command-line interface. It details the specific switches responsible for storing file timestamps, how to synchronize the archive timestamp with its contents, and the best practices for maintaining accurate time metadata across different operating systems.

The Switch to Preserve Modification Times: -mtm

In 7-Zip, the command-line switch used to control and preserve original file modification timestamps is -mtm.

By default, the 7z archive format preserves the last modification timestamp (M-Time) for files. However, you can explicitly enforce this behavior using:

-mtm=on

To disable saving modification times, you would use -mtm=off.

Example Command

To create an archive while explicitly preserving original modification dates:

7z a -mtm=on archive.7z C:\path\to\files\*

Setting the Archive Timestamp: -stl

If your goal is to make the resulting .7z or .zip archive file itself match the modification time of the most recently modified file inside it, use the -stl switch (Set Archive Timestamp).

7z a -stl archive.7z C:\path\to\files\*

Without -stl, the archive file receives the current system time at the moment of creation. With -stl, the archive's modification time matches the newest internal file.


Preserving Full Timestamps (Creation and Access Times)

To preserve complete temporal metadata alongside modification times, 7-Zip provides complementary switches for creation and access times:

  • -mtc=on: Preserves original file creation times (C-Time).
  • -mta=on: Preserves original file last access times (A-Time).
  • -mtm=on: Preserves original file last modification times (M-Time).

Full Timestamp Preservation Example

7z a -mtm=on -mtc=on -mta=on backup.7z C:\data\*

Restoring Timestamps During Extraction

When extracting files with full directory structures, use the x command rather than the e command:

7z x archive.7z -o"C:\destination"

The x command restores both directory trees and the original modification timestamps recorded inside the archive. Modern versions of 7-Zip also restore directory modification timestamps automatically once all files within that directory have finished extracting.