Самый простой способ - использовать команду mdls
. mdls
перечислены атрибуты метаданных для указанного файла. Вот пример выходных данных для файла .png, который у меня есть на рабочем столе.
$ mdls ~/Desktop/hipchat.png
_kMDItemOwnerUserID = 205009058
_kTimeMachineIsCreationMarker = 1
_kTimeMachineNewestSnapshot = 4001-01-01 00:00:00 +0000
_kTimeMachineOldestSnapshot = 2016-06-10 19:25:01 +0000
kMDItemBitsPerSample = 32
kMDItemColorSpace = "RGB"
kMDItemContentCreationDate = 2016-06-10 19:37:53 +0000
kMDItemContentModificationDate = 2016-06-10 19:37:53 +0000
kMDItemContentType = "public.png"
kMDItemContentTypeTree = (
"public.png",
"public.image",
"public.data",
"public.item",
"public.content"
)
kMDItemDateAdded = 2016-06-10 19:45:06 +0000
kMDItemDisplayName = "hipchat.png"
kMDItemFSContentChangeDate = 2016-06-10 19:37:53 +0000
kMDItemFSCreationDate = 2016-06-10 19:37:53 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "hipchat.png"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 80
kMDItemFSOwnerUserID = 205009058
kMDItemFSSize = 22994
kMDItemFSTypeCode = ""
kMDItemHasAlphaChannel = 0
kMDItemKind = "Portable Network Graphics image"
kMDItemLogicalSize = 22994
kMDItemOrientation = 0
kMDItemPhysicalSize = 24576
kMDItemPixelCount = 74520
kMDItemPixelHeight = 81
kMDItemPixelWidth = 920
kMDItemResolutionHeightDPI = 0
kMDItemResolutionWidthDPI = 0
Затем вы можете извлечь информацию, которую вы ищете, вот так.
$ mdls ~/Desktop/hipchat.png |grep -e kMDItemContentCreationDate |awk '{print "Created on "$3" at "$4}'
Created on 2016-06-10 at 19:37:53
$ mdls ~/Desktop/hipchat\ poll.png |grep -e kMDItemContentModificationDate |awk '{print "Modified on "$3" at "$4}'
Modified on 2016-06-10 at 19:37:53