DirectNET

Data Center Management Solutions including UPS Systems, Data Center Cooling, KVM over IP & IP Power Strips, Server Racks and Server Rack accessories; KVM Switches and KVM Extenders; Rackmount Monitors and Rackmount Keyboards.


NAVIGATION
Home
Store
INSIDE MAC
Television Shows
Broadcast Shows
Daily News Shows
Special Shows
EVENTS
DAILY TIPS
Design
Mac OS X
Mac OS X UNIX
COMMUNITY
Forums
Surveys
NEWS
Current
Press
Archive
FEATURES
Editorial
Dr. Mac
Reviews
Reader Reports
RESOURCES
FAQ
Documentation
Learning Center
MAN pages
Glossary
Tutorials
Tips
Links

OUR PARTNERS

OSXFAQ Mac OS X UNIX Tip-of-the-Day  back to index

Spotlight - Reveal the Metadata

By Adrian Mayo - Editor - OSXFAQ

I'm sure you're familiar with Apple's Spotlight and its powerful search capabilities. It searches file content rapidly using a pre-built content index database. It also searches for information about files, making use of metadata. Metadata is data about data. For example, an image created by Photoshop contains data that is the image itself, but the filename, date stamp, owners, file size, and such like form the metadata.

(Note: Spotlight was introduced in Mac OS X Tiger 10.4)

Apple, being a nice Unix player, has opened up the power of Spotlight to the command line. Let's look at what's available in Terminal land.

The 'mdls' command (metadata ls) shows all metadata attached to a file or directory. For example, if we mdls a TextEdit file saved in Rich Text format we see:

$ mdls schedule.rtf 
schedule.rtf -------------
kMDItemAttributeChangeDate     = 2006-02-06 00:59:21 +0000
kMDItemContentCreationDate     = 2004-06-03 17:17:17 +0100
kMDItemContentModificationDate = 2006-02-06 00:59:21 +0000
kMDItemContentType             = "public.rtf"
kMDItemContentTypeTree         = ("public.rtf", "public.text", "public.data", "public.item", "public.content")
kMDItemDisplayName             = "schedule"
kMDItemFSContentChangeDate     = 2006-02-06 00:59:21 +0000
kMDItemFSCreationDate          = 2004-06-03 17:17:17 +0100
kMDItemFSCreatorCode           = 0
kMDItemFSFinderFlags           = 16
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 1
kMDItemFSLabel                 = 0
kMDItemFSName                  = "schedule.rtf"
kMDItemFSNodeCount             = 0
kMDItemFSOwnerGroupID          = 501
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 7607
kMDItemFSTypeCode              = 0
kMDItemID                      = 923169
kMDItemKind                    = "Rich Text Format (RTF) document"
kMDItemLastUsedDate            = 2006-02-06 00:59:21 +0000
kMDItemUsedDates               = (
    2006-01-14 00:00:00 +0000, 
    2006-01-20 00:00:00 +0000, 
    2006-01-21 00:00:00 +0000, 
    2006-01-23 00:00:00 +0000, 
    2006-02-05 00:00:00 +0000, 
    2006-02-06 00:00:00 +0000
)

You'll see all the usual metadata normally displayed by 'ls -l', such as filename name:

kMDItemFSName                  = "schedule.rtf"

and user and group owner (shown as numeric IDs - the translation to textual names is performed by ls):

kMDItemFSOwnerGroupID          = 501
kMDItemFSOwnerUserID           = 501

You'll notice other metadata too, such as:

kMDItemDisplayName - the name as shown in the Finder, which often means without the extension.

kMDItemKind - the type of content.

Metadata with the types kMDItemFS* is information from the filesystem. Other metadata types concern the file contents and is not information that ls reports.

BTW, Spotlight stores its content index and metadata store are held in a directory at the top level of each file system:

$ sudo ls  /.Spotlight-V100/
.journalHistoryLog ContentIndex.db    _exclusions.plist  store.db
.store.db          _IndexPolicy.plist _rules.plist

Each file system has its own Spotlight store ensuring that this information travels with the files to which it belongs.

Tomorrow, we'll look at what metadata is available for other types of file content.


Visit the Site of the Book of the Unix Tips:


Discuss this trick in the OSXFAQ Learning Center forum

E-mail your comments or suggestions to webmaster@osxfaq.com


Copyright © 2000-2008 Inside Mac Media, Inc. All rights reserved.
Apple assumes no responsibility with regard to the selection, performance, or use of the products or services. All understandings, agreements, or warranties, if any, take place directly between the vendors and prospective users.
Apple, the Apple logo, Mac, PowerMac G4, PowerMac G5, Xserve, Xserve RAID, PowerBook, iBook, Airport, AirPort Extreme, iMac, eMac, iLife, iMovie, iCal, iPhoto, iTunes, QuickTime, FireWire, iPod, iSight, AppleWorks, Macintosh, Jaguar, Panther, Mac OS, Mac OS X and Mac OS X Server are trademarks of Apple Computer, Inc.