CLI commands that let you access meta data of all files in OSX


Two small commands with huge possibilities:

  1. mdls 
    usage: mdls [-name attr] [-raw [-nullMarker markerString]] [-plist file] path
    list the values of one or all the attributes of the specified file
    -raw: don't print attribute names before values
    -nullMarker: substitute this string for null attributes in raw mode
    -plist: output attributes in XML format to file. Use - to write to stdout
    option -plist is incompatible with options -raw, -nullMarker, and -name
    example: mdls ~/Pictures/Birthday.jpg
    example: mdls -name Keyword ~/Pictures/Birthday.jpg
  2. mdfind
    Usage: mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]
    list the files matching the query
    query can be an expression or a sequence of words
    
    	-live             Query should stay active
    	-count            Query only reports matching items count
    	-onlyin <dir>     Search only within given directory
    	-name <name>      Search on file name only
    	-s <name>         Show contents of smart folder <name>
    	-0                Use NUL (``\0'') as a path separator, for use with xargs -0.
    
    example:  mdfind image
    example:  mdfind -onlyin ~ image
    example:  mdfind -name stdlib.h
    example:  mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'"
    example:  mdfind -live MyFavoriteAuthor
, , , , , , , ,

Leave a Reply