mac OS X file metadata utilities
mdimport, mdutil, mdcheckschema,
mdls
mdfind -- finds files matching a metadata query
mdfind [-live] [-count] [-onlyin directory] query
Consults the central metadata store and returns a list of files that match the metadata query.
The query can be a string or a query expression.
-0 | outputs an NULL after each result path. useful with xargs -0.
| -live Causes the mdfind command to provide live-updates to the number of files matching the
query. When an update causes the query results to change the number of matches is updated.
The find can be cancelled by typing ctrl-C.
-count
-onlyin dir | Limit the scope of the search to dir
‑interpret as if the user had typed the string into the Spotlight menu.
For example, the string "search" would produce the following query
string:
(* = search* cdw || kMDItemTextContent = search* cdw)
| -literal | don't interpret
| | | | | | | |
EXAMPLES
returns all files with any metadata attribute value matching the string "image":
mdfind image
returns all files that contain "MyFavoriteAuthor" in the kMDItemAuthor metadata attribute:
mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'"
This returns all files with any metadata attribute value matching the string "skateboard". The find
continues to run after gathering the initial results, providing a count of the number of files that
match the query.
mdfind -live skateboard
To open all the files in Preview :
$ mdfind -onlyin /Users/shared/books "kiss kate" | xargs open
To make the search term more selective, use grep and regular expressions.
$ cat file1.txt
Kiss me
$ cat file3.txt
Kiss me, kate
$ mdfind -onlyin /Users/saruman/splotlight-test "kiss me,"
/Users/saruman/splotlight-test/file1.txt
/Users/saruman/splotlight-test/file3.txt
The comma is ignored by spotlight. Using grep:
$ mdfind -onlyin /Users/saruman/splotlight-test "kiss me," | xargs grep -i "Kiss me,"
/Users/saruman/splotlight-test/file3.txt:Kiss me, kate
grep: /Users/saruman/splotlight-test/file: No such file or directory
grep: 4.txt: No such file or directory
$
Use grep to make the search term case sensitive.
The command failed on the filename file 4.txt because it contains a space. Specify option -0 (zero) to both mdfind and xargs .
$ mdfind -0 -onlyin /Users/saruman/splotlight-test "kiss me," | xargs -0 grep -i "Kiss me,"
/Users/saruman/splotlight-test/file3.txt:Kiss me, kate
/Users/saruman/splotlight-test/file 4.txt:Kiss me, kate
|
mdfind, mdutil, mdcheckschema,
mdls
mdimport -- import file hierarchies into the metadata datastore.
mdimport [-VXLrg] [-d level | category] [-w delay] file | directory
import metadata from files or file system hierarchies.
-A | output the attributes and their localizations in the current language
| -X output the schema
mdimport -X
2008-03-27 20:54:56.169 mdimport[287:10b] Schema: id(501) (null)
| -r Ask the server to reimport files for UTIs claimed by the listed plugin.
reimport all of the chat files on the system to be :
mdimport -r /System/Library/Spotlight/Chat.mdimporter
| -L | list of installed importers
| -d level | set debug level 1-4
| -p | output performance information
| -V | output timing information
| -n | Don't actually set the attributes on the file. Useful for debugging.
| ‑w msecs | Wait for the specified interval between scanning files.
| -g plugin | Load the plugin at the provided path, ignoring system installed plugins. Useful for testing plugins that have not yet been installed.
| | | | | | | | |
|
mdfind, mdimport, mdcheckschema,
mdls
mdutil -- manage the metadata stores used by Spotlight
mdutil [-pEsav] [-i on | off] volume ...
-i on | off | Sets the indexing status for volumes .
may be delayed due to low disk space or other conditions.
|
-a | all volumes.
| -s| output status
| -v verbose
mdutil -s -a
/Volumes/PHOTOS:
Indexing and searching disabled.
/:
Indexing and searching disabled.
/Volumes/BACKUPS/Backups.backupdb:
Indexing enabled.
Scan base time: 2008-03-24 19:29:35 -0400 (264962 seconds ago), reasoning: 'scan required - mount side'
/Volumes/DATA-1:
Indexing disabled.
/Volumes/DATA:
Indexing and searching disabled.
/Volumes/BACKUPS:
Indexing and searching disabled.
| -p | Flush local caches to the network device.
| -E | erase. The stores may be rebuilt
| | | | | |
mdfind, mdimport, mdutil,
mdls
mdcheckschema schema.xml [...]
The mdcheckschema command validates the mdimporter schema files provided as arguments and indicates
whether the schema could be successfully parsed.
mdfind, mdimport, mdutil,
mdcheckschema
mdls -- lists the metadata attributes for the specified file
mdls [-name attributeName] [-raw [-nullMarker markerString]] file ...
outputs the values of all the metadata attributes associated with files
-name attributeName| only matching metadata attribute. multiple occurances permitted
| -raw output raw attribute data in the order that was requested.
Fields separated with a NULL useful with xargs -0.
| -nullMarker markerString | Sets a marker string to be used when a requested attribute is null. Only with -raw . Default is null
> mdls 0installScreen-090502
kMDItemContentCreationDate = 2009-05-03 10:16:14 -0400
kMDItemContentModificationDate = 2009-05-03 10:16:14 -0400
kMDItemContentType = "public.data"
kMDItemContentTypeTree = (
"public.data",
"public.item"
)
kMDItemDisplayName = "0installScreen-090502"
kMDItemFSContentChangeDate = 2009-05-03 10:16:14 -0400
kMDItemFSCreationDate = 2009-05-03 10:16:14 -0400
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = 0
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = 0
kMDItemFSLabel = 0
kMDItemFSName = "0installScreen-090502"
kMDItemFSNodeCount = 0
kMDItemFSOwnerGroupID = 80
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 185107
kMDItemFSTypeCode = ""
kMDItemKind = "Plain text"
kMDItemLastUsedDate = 2009-05-03 10:16:14 -0400
kMDItemUsedDates = ( 2009-05-03 00:00:00 -0400)
| | |
mdattributes
ContentTreeType
public
.data, .item, .folder, .directory, .content .text, .plain-text, .html, .executable
.unix-executable, .composite-content, .source-code, .shell-script, .script, .content,
.perl-script, .log
com.microsoft.word.doc,
com.adobe.pdf,
com.netscape.javascript-source,
com.microsoft.excel.xls,
com.apple.log,
com.apple.finder.burn-folder,
Mac OS X Oct 27, 2004