关于文件导致在“ls”命令中文件属性相等

关于文件导致在“ls”命令中文件属性相等

我有一个文件夹,里面有数千张图片。 在这数千张图片中,我想把那些“上次创建”和“上次修改”属性完全相同的图片放在一起。 (换句话说,我想把所有我从未重命名过的图片分开)

有没有办法从终端做到这一点?

这是我想要连接的两个命令 ls-tU按创建日期列出文件。(我用的是 Mac) ls -lt按修改日期列出文件

我想要 “列出创建日期 = 修改日期的文件”

答案1

最简单的方法可能是使用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

相关内容