0

Is there a way to rewrite the last modified date of all the files inside a .zip file to the date of extraction?

Basically, whenever someone unzips the archive, the last modified date of all files is changed to the date of the zip extraction?

  • 1
    To reword (and double-check): you want the extracted filenames to have a current timestamp and not the one that zip reassigns? Or do you want to re-date files that are inside of a zip file? – Jeff Schaller Apr 5 at 11:03
  • do you want to re-date files that are inside of a zip file? – aramko aramko Apr 5 at 14:33
3

With libarchive bsdtar (supports all sorts of archive formats, including pkzip's), use the m flag:

bsdtar xmf file.zip

From the manual:

-m, --modification-time
(x mode only) Do not extract modification time. By default, the modification time is set to the time stored in the archive.

Note that the m flag is not specific to bsdtar, it was already there in the first implementation of tar in Unix V7 in 1979. What is specific to bsdtar is the support for archive formats other than tar.

With unzip, see the -DD option.

  • Both options worked out for me! I just have one question. Whenever I use bsdtar xmf file.zip or unzip -DD file.zip a new __MACOSX folder is created. Is there a way to avoid that? – Johnny Apr 5 at 11:13
  • @Johnny That has nothing to do with the question at hand. The directory is likely part of the archive, and if you don't need its contents you could probably just follow up with a rm -r __MACOSX after extraction. – Kusalananda Apr 5 at 11:42
  • Answer comments are not for asking questions. unix.stackexchange.com/q/510704/5132 is how one asks a question. – JdeBP Apr 5 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.