I'm recovering files from an old hard drive and I need to keep the last modified date from the drive. The reason they are updating is because I need to change the ownership of the files to a new user.
1 Answer
The mtime (file modification time) shouldn't change when the owner is changed (nor should the atime or access time). That would be a change in the inode information, reflected in the ctime field.
If you find that on your system, chown(2) (or chown(1) and chgrp(1)) do change the mtime or atime and you're concerned about preserving both mtime and atime, then you'll need to write code to collect the current times (using stat(2) or stat(1)), and reinstate them (using utimes(2) or touch(1)).
AFAIK, you cannot control the setting of the ctime. If the inode changes, the system records the time it changed and doesn't allow you to change that.
- Hmm, interesting. I assumed that the chown and chgrp commands would be the modifiers on the time. The only other action performed on the files was a transfer from a hard drive to a server using ftp via Filezilla. Would this cause the time change?Alexandertyler– Alexandertyler2012-09-12 17:51:10 +00:00Commented Sep 12, 2012 at 17:51
- 1When I just used FTP to copy a file between machines (default options), the modification time of the file on the target machine was set to the current date, not to the original date. So FTP does not preserve mtime and atime timestamps by default. This isn't very surprising; FTP is more general than Unix with its mtime and atime. Put another way, FTP is not TAR. Maybe you should consider using TAR to package the files on the source machine, use FTP to transfer the (compressed) tar file, and then use TAR on the target to restore with the correct time stamps. You can then adjust ownership later.Jonathan Leffler– Jonathan Leffler2012-09-12 18:17:17 +00:00Commented Sep 12, 2012 at 18:17