4

why cp -p does not keep ctime?

I think all timestamps should be preserved as described

   --preserve[=ATTR_LIST]
          preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all

[root@node101 test]# stat 1
  File: ‘1’
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 54395143    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-08-08 11:00:04.207486784 +0800
Modify: 2019-08-08 11:00:04.207486784 +0800
Change: 2019-08-08 11:00:04.207486784 +0800
 Birth: -
[root@node101 test]# cp -p 1 2
[root@node101 test]# stat 2
  File: ‘2’
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 54395144    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-08-08 11:00:04.207486784 +0800
Modify: 2019-08-08 11:00:04.207486784 +0800
Change: 2019-08-08 11:00:28.478788113 +0800
 Birth: -
L.SG
  • 121
  • 1
  • 5
  • 1
    From `info cp` on CentOS, under `-p`/`timestamps`: "Preserve the times of last access and last modification, when possible." Relevant: [How can I change 'change' date of file?](https://unix.stackexchange.com/questions/36021/how-can-i-change-change-date-of-file) – Amadan Aug 08 '19 at 03:29
  • Note the conspicuous absence of `ctime` in that quote. – Amadan Aug 20 '19 at 07:08
  • 3q, I got it. 'timestamps' Preserve the times of last access and last modification, when possible. On older systems, it is not possible to preserve these attributes when the affected file is a symbolic link. However, many systems now provide the 'utimensat' function, which makes it possible even for symbolic links. – L.SG Aug 20 '19 at 07:10

0 Answers0