ILD

tar preserve nanoseconds timestamps
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2025-3-25 站点:Inside Linux Development

今天用tar解压的时候,发现文件的modify time,只精确到秒。


$ stat linux-6.12.y/Makefile

  File: linux-6.12.y/Makefile

  Size: 68794           Blocks: 136        IO Block: 4096   regular file

Device: 802h/2050d      Inode: 4399981     Links: 1

Access: (0644/-rw-r--r--)  Uid: ( 1000/    yuan)   Gid: ( 1000/    yuan)

Access: 2025-03-25 14:29:57.669627075 +0800

Modify: 2024-12-18 18:58:52.000000000 +0800

Change: 2025-03-25 14:29:57.669627075 +0800

 Birth: -


原来,要默认的gnu格式,不支持纳米精度,需要使用posix格式:

-H posix

或者 --format posix

或者 --posix


$ tar --posix -cf a.tar abc/a

$ tar xf a.tar -C abcd

$ stat abcd/abc/a

  File: abcd/abc/a

  Size: 0               Blocks: 0          IO Block: 4096   regular empty file

Device: 802h/2050d      Inode: 4399987     Links: 1

Access: (0664/-rw-rw-r--)  Uid: ( 1000/    yuan)   Gid: ( 1000/    yuan)

Access: 2025-03-25 15:01:08.434095836 +0800

Modify: 2025-03-25 14:46:14.934762384 +0800

Change: 2025-03-25 15:01:08.434095836 +0800

 Birth: -


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.