檔案時間記錄的讀取
問題:對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
等其它用處也可以參考