I have multiple .tgz kernel-panic logs that I must extract from one file. The timestamps for these .tgz files are important. Whenever I use the following:tar - zvxf paniclogs.tgz
-rwxrwxrwx 1 root root 22359 Feb 22 15:03 kernel-panic-20190213020406-3.tgz
-rwxrwxrwx 1 root root 22971 Feb 22 15:03 kernel-panic-20190213020844-2.tgz
-rwxrwxrwx 1 root root 28344 Feb 22 15:03 kernel-panic-20190213101549-1.tgz
-rwxrwxrwx 1 root root 30683 Feb 22 15:03 kernel-panic-20190213154050-0.tgzIt extracts the logs but changes the timestamps to the date and time when I extracted them. This is not the case when I use Cygwin. I know there must be a way to extract these logs and preserve the time stamps. Can you please assist? Thank you.
01 Answer
This cannot be done with GNU tar. However there is a lesser known utility star, developed by Jörg Schilling, which will accomplish exactly what you are after. I will demonstrate how this works.
First we can examine a single file within a test tgz archive and demonstrate its timestamp, which I have highlighted below to make the terminal output perfectly clear:
andrew@ilium$ tar -tv --full-time -f test.tgz mp3enc31/readme.txt
-rw-r--r-- sir/inel 937 1998-11-06 00:28:41 mp3enc31/readme.txt ^^^^^^^^^^As you have found when you extract this file in the customary manner with tar the access time (and the change time) is altered. Again I have altered the terminal output to easily show this:
andrew@ilium~$ tar -xf test.tgz mp3enc31/readme.txt
andrew@ilium~$ stat mp3enc31/readme.txt File: readme.txt Size: 937 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 56885505 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ andrew) Gid: ( 100/ users)
Access: 2019-02-23 17:13:55.385500219 +1100 <--------------------
Modify: 1998-11-06 00:28:41.000000000 +1100
Change: 2019-02-23 17:13:55.385500219 +1100 <-------------------- Birth: -
andrew@ilium~$ However if we use the star utility as sudo, (note that sudo is required for the ctime modification) you will see that all access times are preserved:
andrew@ilium~$ sudo star -xza -ctime < test.tgz mp3enc31/readme.txt
star: 62 blocks + 0 bytes (total of 634880 bytes = 620.00k).
andrew@ilium~$ stat mp3enc31/readme.txt File: readme.txt Size: 937 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 59377688 Links: 1
Access: (0644/-rw-r--r--) Uid: (30076/ UNKNOWN) Gid: (30000/ UNKNOWN)
Access: 1998-11-06 00:28:41.000000000 +1100 <--------------------
Modify: 1998-11-06 00:28:41.000000000 +1100
Change: 1998-11-06 00:28:41.000000000 +1100 <-------------------- Birth: -
andrew@ilium~$The star man pages advise some caution with the -ctime option as it can confuse cron, the news system and even slow the system clock. So just be a little careful!
References:
- man pages for star: Documentation for all of the options used above and demonstration of the many other options available.