tar -cf 不保留确切的修改时间

ste*_*eve 4 tar

使用 tar 创建 tar 存档时-c,修改时间似乎在变化,特别是它截断了小数点后的时间,使 modtime 只是它原来的整数值。

注意:```

[localhost] $ mkdir test
[localhost] $ stat test
  File: ‘test’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Modify: 2016-07-18 17:01:33.116807520 -0400 # <------ Notice exact time
[localhost] $ tar -cf test.tar test
[localhost] $ tar -xf test.tar
[localhost] $ stat test
  File: ‘test’
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Modify: 2016-07-18 17:01:33.000000000 -0400 # <------ Notice how time is rounded
Run Code Online (Sandbox Code Playgroud)

stat为了可读性,我从输出中删除了不相关的部分)

我已经询问过man tar,但找不到可以以纳秒为单位保留精确修改时间的选项。有人可以解释为什么会发生这种行为吗?或者这是在 tar 创建期间预期的。

更新:到目前为止没有运气,我尝试使用tar选项,但大多数处理时间的选项都与文件的访问时间有关,而不是 modtime。处理 modtime 的那些会更改modtime,这不是我要找的东西。

小智 5

以防万一有人在谷歌上搜索同样的问题时偶然发现这个线程(就像我做的那样):

解决方案(至少其中之一)是使用该-H选项,如下所述:

https://unix.stackexchange.com/questions/397130/tar-how-to-preserve-timestamps-down-to-more-than-a-second-of-precision/397132#397132

tar(1)手册页并没有指出的实际影响-H在所有参数; 我想,如果一个可能的关键字的搜索(这将是非常有益的"nanosecond""second""resolution"等)导致的段落-H