问题:对Mac OS X 进行文件时间信息的获取中需要获取文件的历史打开时间

首先,对于Linux下:

一个文件有三种时间,分别是:访问时间、修改时间、状态时间,没有创建时间。

但是在Mac OS X下除了Linux上的三种时间,可以发现还有创建时间。

各个时间的含义大概如下:

创建时间(created)  Mac OS X下文件写到磁盘上时记录的时间,一般是首次添加时间。
修改时间 (modified)mtime 只有修改文件内容,这个时间才变,修改文件名不算。
变更时间 (change)ctime 当文件的属性发生变化(比如改变权限或者所有关系)时,ctime的值就会被改变。
访问时间(last opened,Access): atime(要文件被访问(比如运行或读取),它就会被修改)


单独查看三个时间的操作

除了可以通过stat来查看文件的mtime,ctime,atime等属性,也可以通过ls命令来查看,具体如下:

ls -lc filename 列出文件的 ctime (最后更改时间)

ls -lu filename 列出文件的 atime(最后存取时间)

ls -l filename 列出文件的 mtime (最后修改时间)


复制文件或者移动文件的时候,文件的哪些时间会变化呢?



再对Mac OS X来说,其实上面多了的内容是为spotlight 服务的,可以通过Common Metadata Attribute Keys 的属性来获取。

可以参考:

1.Common Metadata Attribute Keys 

​https://developer.apple.com/documentation/coreservices/mditem/common_metadata_attribute_keys​

kMDItemLastUsedDate
kMDItemFSContentChangeDate



2.Spotlight syntax, mdfind examples, and metadata attributes

​http://osxnotes.net/spotlight.html​

对这些item做了详细介绍。

另外对时间读取的命令可以参考:

1,mdls


uyis-iMac:Downloads julius$ mdls /Users/julius/Downloads/Quicken_Home_Business_2017.zip 
_kMDItemOwnerUserID = 501
kMDItemContentCreationDate = 2017-08-01 02:10:02 +0000
kMDItemContentModificationDate = 2017-08-01 02:35:21 +0000
kMDItemContentType = "public.zip-archive"
kMDItemContentTypeTree = (
"public.zip-archive",
"com.pkware.zip-archive",
"public.data",
"public.item",
"public.archive"
)
kMDItemDateAdded = 2017-08-01 02:10:02 +0000
kMDItemDisplayName = "Quicken_Home_Business_2017.zip"
kMDItemFSContentChangeDate = 2017-08-01 02:35:21 +0000
kMDItemFSCreationDate = 2017-08-01 02:10:02 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "Quicken_Home_Business_2017.zip"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 229824432
kMDItemFSTypeCode = ""
kMDItemKind = "ZIP archive"
kMDItemLastUsedDate = 2017-08-01 03:20:46 +0000
kMDItemLogicalSize = 229824432
kMDItemPhysicalSize = 229826560
kMDItemUseCount = 1
kMDItemUsedDates = (
"2017-07-31 16:00:00 +0000"
)



2,stat


juyis-iMac:Downloads julius$ stat /Users/julius/Downloads/Quicken_Home_Business_2017.zip 
16777221 26775129 -rw-r--r-- 1 julius staff 0 229824432
"Aug  4 13:50:22 2017"
"Aug  1 10:35:21 2017"
"Aug  1 10:35:21 2017"
"Aug  1 10:10:02 2017"
4096 448880 0


3,​​mdfind​​​, ​​ mdutil​​ ,GetFileInfo

等其它用处也可以参考