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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI 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?
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.