How can I modify/open files without changing last modified/opened date on Mac OS (or Linux)?

2

My dad passed away last year, so I have boxes of dozens of old hard drives (all HFS+) with my all his files and pictures on them. I want to copy everything into one drive/RAID (also HFS+, possibly APFS) and then reorganize, dedup, and make a backup of that singular array so all the files are in a known safe state. I would like to do all that without changing any of the file's or folder's 'created', 'last modified' or 'last opened' times. Specifically I would like to:

  1. Move/delete files/folders without changing their containing folder's 'last modified' time
  2. Move/rename files/folders without changing their own 'last modified' time
  3. Open files (to inspect and compare them) without changing their own 'last opened' time
    • the Finder in macOS has Quick Look, which enables me to look at files without opening them but sometimes it is helpful to actually open things, so other ideas would are welcome
    • mounting the drive in read-only is an option when only opening files, but still need to move files around after opening them, so I'd have to remount, making it a clumsy solution

I didn't list copying items to the destination since I know that there are ways to copy files without changing any of that data (rsync comes to mind), meaning it shouldn't be too hard to plug a drive in, rsync the whole thing into a folder, eject, and rinse and repeat. What I haven't figured out yet is how to do the things I listed above, so any ideas for how to move, delete, rename, or open files without modifying their metadata would be appreciated.

RTHarston

Posted 2018-01-20T23:01:20.300

Reputation: 141

If you make a partition-to-partition (or disc-to-disc) copy, all the file time data will be preserved. Any attempt to access on a file-by-file basis will update the access time, though the modification time will be unaffected: any new directories created will bear the modification time when the last file was added or deleted, but the original directories will retain their modification times. – AFH – 2018-01-20T23:17:49.730

A solution that comes to mind is to use touch -r actual shadow to copy access and modification time to "shadow" files in a "shadow" tree (and then make that all R/O), and then use touch -r shadow actual to restore them in case of need. touch -r also works with directories. Of course you would have to process directories last. – xenoid – 2018-01-20T23:33:26.627

You could maybe tar up the files, and then only extract the ones you want. Directory modification times should be set to the original time, but you'll only have the files you want. You'll have to extract everything in one go, though, so you'd need to know ALL the files you want, and someone put that into the tar extract command. Personally, I like @xnenoid's touch -r recommendation... – jimtut – 2018-01-21T03:05:34.557

@AFH Thank you for the comment. I am aware that the modification time will stay the same, that I'm not as worried about. It is that file-by-file update to the access time that want to avoid. I don't want to disturb any of the history of the files and directories so they appear like they will appear as if they haven't changed, except I do want to reorganize and delete duplicates. – RTHarston – 2018-01-24T08:52:13.087

@xeniod Hum... Thanks for the idea, it sounds promising. I'll have to try it. I knew there was a way to save and restore the times but for some reason I didn't think it would be that easy. It might be a little while before I can run some tests and see if that will work for what I am doing, but I'll keep you posted on how it goes. It may just be exactly what I was looking for. ;) – RTHarston – 2018-01-24T08:54:34.223

@jimtut Thank you for that idea as well. The touch -r idea that xenoid had may be just what I was looking for to maintain the time stamps while I am working on the files, but once I have everything 'set in stone' I think your idea of putting everything in a tar file is a pretty good idea for archiving everything in a way that can't be disturbed (the a in tar does stand for archive after all). Accessing the files individually later isn't so much of a problem. Thanks! – RTHarston – 2018-01-24T09:19:42.937

@BobVicktor - I didn't say so explicitly, but if you make a partition copy and mount that, then you can copy whatever files you need from the copy, without affecting the original time stamps. If it's important, you can restore the copy's time stamps by repeating the partition copy. – AFH – 2018-01-24T11:18:46.080

@AFH Ah, thank you. Sorry I didn't see what you meant the first time. That isn't a bad idea actually, and I'll probably use that sometime, but in this case I'm not sure if I want to do that for every drive since there are actually boxes and boxes of them... He used old 10 and 20 GB drives as 'backups' but in reality his files are scattered across all of them and I have no idea what is where, so I want to consolidate all the files into one big drive. One option I was thinking about trying is making a partition to disk image copy, and mounting the disk image as read only. – RTHarston – 2018-02-17T20:44:20.770

At first glance, what about a partition for each small disc, so that your big discs will still reflect the original disc structure? GPT allows 128 partitions, and you can still mount each partition as read-only when you want to access it. – AFH – 2018-02-17T22:25:35.430

Answers

0

Well. This recently passed 1k views! Wow! I find that a bit odd/strange/curious considering at the time of writing this answer it has one upvote and no answers...

Apparently there is a badge for that, so I got a notification which brought this old question back to my attention. So I decided to show it to a co-worker and he had a pretty good idea that I'd like to share.

This may not be the 'best' solution, and would need a bit of work to get set up, but should do the trick.

The idea: Make a log file that contains the timestamp info for all the files, so if I do make modifications all the previous times are still in that log file.

Even if I open a bunch of things or move some files around, knowing I can see their original timestamps in that file is enough for my needs and that is probably all I'm going to do. It shouldn't be too hard to figure out the right command to get that info and pipe it in to a file.

And...

...in theory it should be possible to parse those timestamps back out of the file and re-apply them to files that I have opened or folders I have deleted items from, fully answering my original question. It is this part that would probably take a bit more work to do, so I don't know if I'll do it. But it is reassuring to know that with the file logging the original timestamps, it should be theoretically possible to do.

RTHarston

Posted 2018-01-20T23:01:20.300

Reputation: 141