find: filter by added time

0

I know it is possible to filter by modified time by using modifier -mtime, but I would like to filter by the time the file was added

I'm on mac and I see added time in finder

Capture

NeDark

Posted 2019-03-03T18:37:51.530

Reputation: 253

Answers

1

The HFS filesystem supports several different timestamps on files. The normal Unix timestamps are there - "modification time", "change time", "last access time", and there is also "creation time" which is HFS-specific.

To see the standard timestamps for a file, use "stat -x FILE". You can also see them individually with various options to "ls" but this is less confusing.

Now things get weird. I'm testing on MacOS 10.13 (High Sierra). The "stat" command without any options is supposed to show you all the timestamps, and indeed it does show 4 timestamps, but the 4th one it shows seems to be a duplicate of the modification time. The GetFileInfo command with no options is supposed to print out the creation and modification time, but on my machine it clearly prints the mod time for both values. "ls -Ul" is supposed to list out the creation time, but again, it shows me the modification time.

I suspect the "Date Added" field in Finder is the HFS inode creation time, and I wouldn't expect any standard Unix command to be able to see that unless it had specific extensions for MacOS. Apple did seem to add hooks to "find", "ls", and "stat" to use the creation time field, but it doesn't look like they did so with rsync. And given the results of my testing I don't think I'd want to rely on their changes even if they did.

So the answer for rsync appears to be "no, you can't do that."

I'm wondering why you think you need to filter that way for rsync - rsync's job is to find changed files and copy them, filtering by date added doesn't buy you anything because a file could get changed and not have its creation date updated.

Velo Traveler

Posted 2019-03-03T18:37:51.530

Reputation: 139

Sorry, I entered rsync by mistake, but the question was actually about the find command. Thanks for your answer, I have edited my question – NeDark – 2019-03-04T08:44:05.950

My answer mentioned "find" as one of the commands Apple modified to support parsing inode creation times - read through "man find" to see the description of the "-Btime" option. I recommend you double-check with "stat" and "ls -Ul" to make sure you're not seeing duplicates of the mod time as I'm seeing on my Mac. – Velo Traveler – 2019-03-06T14:33:28.153