It is due to what the timestamps mean. Take a look at https://linux.die.net/man/2/stat
The field st_atime is changed by file accesses, for example, by execve(2), mknod(2), pipe(2), utime(2) and read(2) (of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.
The field st_mtime is changed by file modifications, for example, by mknod(2), truncate(2), utime(2) and write(2) (of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.
The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).
A copy of a file, maintains some of the attributes of the original, and you certainly can preserve timestamps.
If you want to preserve all the timestamps you can do:
then after the copy is done, delete sourceDirectory, if desired. You could also collect all the timestamps, move the structure and then reapply the old timestamps:
The field st_atime is changed by file accesses, for example, by execve(2), mknod(2), pipe(2), utime(2) and read(2) (of more than zero bytes). Other routines, like mmap(2), may or may not update st_atime.
The field st_mtime is changed by file modifications, for example, by mknod(2), truncate(2), utime(2) and write(2) (of more than zero bytes). Moreover, st_mtime of a directory is changed by the creation or deletion of files in that directory. The st_mtime field is not changed for changes in owner, group, hard link count, or mode.
The field st_ctime is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).
A copy of a file, maintains some of the attributes of the original, and you certainly can preserve timestamps.
If you want to preserve all the timestamps you can do:
Code:
cp -r -p /path/to/sourceDirectory /path/to/destination/
Code:
timestamp=$(stat -c %y sourceDirectory)mv sourceDirectory destinationDirectorytouch -d "$timestamp" destinationDirectory
Statistics: Posted by bjtheone — Thu Feb 29, 2024 5:43 pm