Mac OS X Terminal.app中是否有类似的“获取信息”(Cmd + I)功能?


21

我想问一下在OS X中是否有类似的“获取信息”(Cmd + I)功能,但是从Mac OS X Terminal.app中获得了?我的意思是像finderGetInfo /path/to/a/file.ext这样的东西,它将在终端控制台中输出文件的信息?像这样:

在此处输入图片说明

但是从命令行:

Machine:~ antony$ finderGetInfo /Users/antony/file.ext
General:
   Kind: Document
   Size: 29 bytes (4 KB on disk)
   Where: /Users/antony
   Created: Today 08:58
   Modified: Today 08:58
   Stationery pad: NO
   Locked: NO
More Info:
   --
Name & Extension: file.ext
Comments: ...
etc...

当创建一些需要从任何类型的文件中推断出一些有用信息的自动工具时,这将非常有用。

在OS X中可以吗?

Answers:


32

mdls列出文件元数据。下面的文件夹示例

kMDItemContentCreationDate     = 2011-11-20 04:05:42 +0000
kMDItemContentModificationDate = 2014-10-22 01:52:53 +0000
kMDItemContentType             = "public.folder"
kMDItemContentTypeTree         = (
    "public.folder",
    "public.directory",
    "public.item"
)
kMDItemDateAdded               = 2014-10-17 09:19:38 +0000
kMDItemDisplayName             = "temp"
kMDItemFSContentChangeDate     = 2014-10-22 01:52:53 +0000
kMDItemFSCreationDate          = 2011-11-20 04:05:42 +0000
kMDItemFSCreatorCode           = ""
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "temp"
kMDItemFSNodeCount             = 96
kMDItemFSOwnerGroupID          = 80
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = (null)
kMDItemFSTypeCode              = ""
kMDItemKind                    = "Folder"
kMDItemLastUsedDate            = 2014-12-03 03:57:48 +0000
kMDItemUseCount                = 2
kMDItemUsedDates               = (
    "2014-10-25 13:00:00 +0000",
    "2014-12-02 13:00:00 +0000"
)

这真是个好消息,谢谢您这么快回答!
user3019105

是否有一种仅打印特定属性的方法?
Karoh

1
@Horak尝试阅读man mdls
Milliways

1
mdls -name kMDItemContentCreationDate target_file_name_here是一个示例。
jasonleonhard
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.