mdls

List the metadata attributes for a specified file.

Syntax
      mdls [-name attributeName] [-raw [-nullMarker markerString]] file ...

Key
   -name        Print only the matching metadata attribute value.  Can be used multiple times.

   -raw         Print raw attribute data in the order that was requested.
                Fields will be separated with a ASCII NUL character, suitable for piping to xargs(1) -0.

   -nullMarker  Set a marker string to be used when a requested attribute is null.
                Only used in -raw mode.  Default is "(null)".

The mdls command prints the values of all the metadata attributes associated with the files provided as an argument.

To get a list of the available attributes for use in constructing queries, see mdimport(1), particularly the -X switch. Not all files are indexed by spotlight and not all file attributes are present on all files, image files, iCal files and music files all support different attributes.

Examples

Return the application used to create a document:

$ mdls -n kMDItemCreator /Users/fred/Pictures/Untitled.pxm

List all cameras and scanners used to make pictures on my Mac [via StackOverflow]:

$ mdfind -0 kind:image | xargs -0 mdls -n kMDItemAcquisitionModel | sort -u

“The real voyage of discovery consists not in seeking new landscapes but in having new eyes” ~ Marcel Proust

Related macOS commands

Spotlight Metadata Attributes - List of all the kDM* attributes (or just use mdls to list the attributes of a file).
mdfind - Spotlight search.
mdutil - Manage Spotlight metadata store.
mdimport - Import file hierarchies into the Spotlight datastore.
find - Search for files that meet a desired criteria.


 
Copyright © 1999-2024 SS64.com
Some rights reserved