4

I want to unzip a .zip archive, and preserve the timestamps of the files extracted. But this command doesn't preserve the timestamps:

unzip my.zip

I saw this post in 2011, and wonder if there is a solution?

2
  • As you can see in unzip manual[1]: "Normally, unzip tries to restore all meta-information for extracted items that are supplied in the Zip archive (and do not require privileges or impose a security risk)." That includes timestamps. [1]linux.die.net/man/1/unzip
    – alpert
    Oct 24, 2014 at 20:21
  • By "restore", does it mean "preserve"? I understand "restore" to mean "go back to the original", and here "original" are the files in the archive.
    – Tim
    Oct 24, 2014 at 20:24

1 Answer 1

4

Using unzip without and arguments will, by default, extract files and preserve the directory structure and time stamp.

You can use the -l argument to get a listing which will show you the time stamp of the files. The extracted content will match what you see from the listing.

If you see something different with the zip file you're trying to open, can you show us the output of the "-l" listing as well as an ls -l listing of the extracted directory?

Update

Sub-folders retain the timestamp of the zip archive. However, if the folder is on the top level, it will lose the original timestamp and assume the timestamp of when it's extracted.

This is an example. The Ortho4XP.zip file is a zip file that contains over 300 files and subdirectories. Today is August 7, 2017. As you can see from the output the top level directories will assume the date that the archive is unzipped. However, as you can see from the output the other files and sub-directories retain the timestamp of when the files were zipped.

ljames@ubunzeus:~/Downloads/open/del/2$ unzip ~/Downloads/Ortho4XP.zip
ljames@ubunzeus:~/Downloads/open/del/2$ ls -lta
total 888
drwxrwxr-x 17 ljames ljames   4096 Aug  7 17:11 .
drwxrwxr-x  3 ljames ljames   4096 Aug  7 17:11 __MACOSX
drwxrwxr-x  2 ljames ljames   4096 Aug  7 17:11 Licence
drwxrwxr-x  2 ljames ljames   4096 Aug  7 17:11 Archives
drwxrwxr-x 12 ljames ljames   4096 Aug  7 17:11 Patches
drwxrwxr-x  3 ljames ljames   4096 Aug  7 17:11 Previews
drwxrwxr-x  3 ljames ljames   4096 Aug  7 17:11 Utils
drwxrwxr-x  5 ljames ljames   4096 Aug  7 17:11 Install
drwxrwxr-x  3 ljames ljames   4096 Aug  7 17:11 Manual
drwxrwxr-x  5 ljames ljames   4096 Aug  7 17:11 bin
drwxrwxr-x  4 ljames ljames   4096 Aug  7 17:11 ..
-rwxr--r--  1 ljames ljames 389049 Feb 24 19:02 Ortho4XP_devel.py
-rwxr--r--  1 ljames ljames 388606 Jan 12  2017 Ortho4XP_v120b.py
-rwxr--r--  1 ljames ljames  36037 Jan 12  2017 Carnet_d_adresses.py
-rwxr--r--  1 ljames ljames   6716 Sep 12  2016 Ortho4XP.cfg
drwxr--r--  2 ljames ljames   4096 Aug 31  2016 OSM_data
drwxr--r--  2 ljames ljames   4096 Aug 31  2016 Tiles
-rwxr--r--  1 ljames ljames  13332 Jul 10  2016 README.install_NOT_UP_TO_DATE
drwxr--r--  2 ljames ljames   4096 Jul 21  2015 Elevation_data
drwxr--r--  2 ljames ljames   4096 Jul 21  2015 Masks
drwxr--r--  2 ljames ljames   4096 Jul 21  2015 Orthophotos
drwxr--r--  2 ljames ljames   4096 Jul 21  2015 tmp
ljames@ubunzeus:~/Downloads/open/del/2$

Update #2

I'm still studying to figure out what is the difference between the folders that are not retaining the archive timestamp and the ones that are. I'll update the answer to be more definitive soon. It may depend on the option used in creating the zip file.

5
  • Have you actually tried this? unzip will preserve timestamps of files, but not of directories. I'm actually trying to figure this one out as well. Aug 7, 2017 at 20:35
  • Yes, I have tested it. I use it all the time. I'm curious what version of Ubuntu are you running? By the way, give me about 5 minutes to update my answer with examples. Aug 7, 2017 at 20:46
  • @MishaNasledov I tested a number of zip files. Most of them retain the timestamp for all folders. A few of them didn't. I posted an update to my answer. I'm still studying the difference between the instances where the folder timestamp is retained and when it's not. I'll update the answer again when I get a more definitive and consistent result. Aug 7, 2017 at 21:23
  • Sorry, I was being stupid. I was working on a script and it was doing stuff inside the directories after unzip. I was tired and missed it. unzip does in fact do the correct thing per man page. Aug 8, 2017 at 7:35
  • It doesn't work this way with FAT32 or NTFS 3g mounted.
    – Slyx
    Jul 21, 2019 at 9:43

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.