I'll provide the following script to reproduce the problem:
mkdir a
touch a/f
sleep 1
cp -a a b
stat --printf="%u %g %a %z\n" a/f
stat --printf="%u %g %a %z\n" b/f
The result for the two stat
calls will differ in the timestamps:
1000 100 644 2015-04-05 10:53:35.736399836 +0200
1000 100 644 2015-04-05 10:53:36.740399841 +0200
But the manual of cp
tells, that -a
should preserve the timestamps.
What am I doing wrong?
How can I ensure timestamps are kept at the copy in a way I can test for it?
I tried this at Xubuntu 14.04. Thx for any help!
Ps (Important):
I just tried to access timestamps over ls
, there I don't have the same behavior:
$ ls -l --full-time a/
-rw-r--r-- 1 foo bar 0 2015-04-05 10:53:35.736399836 +0200 f
$ ls -l --full-time b/
-rw-r--r-- 1 foo bar 0 2015-04-05 10:53:35.736399836 +0200 f
Am I checking the wrong thing with my stat command? I want to find out if a file as been "changed" by comparing it to a copy in the backup...
stat
prints 3 different times:
- Access - the last time the file was read
- Modify - the last time the file was modified (content has been modified)
- Change - the last time meta data of the file was changed (e.g. permissions)
This explains why the Change time differs between a/f
to b/f
(metadata was updated),
while the Modify time is the same (file's content didn't change upon cp
).
File: `a/f'
...
Access: 2015-04-05 16:15:22.000000000 +0300
Modify: 2015-04-05 16:15:13.000000000 +0300
Change: 2015-04-05 16:15:13.000000000 +0300
File: `b/f'
...
Access: 2015-04-05 16:15:22.000000000 +0300
Modify: 2015-04-05 16:15:13.000000000 +0300
Change: 2015-04-05 16:19:49.000000000 +0300