Skip to content

mdls MacOS command

The MacOS mdls command is a powerful tool for retrieving and displaying metadata information for files on your system. This command allows you to access various details such as file creation date, file type, pixel dimensions for images, and much more. By running the mdls command followed by the file path, you can quickly gather valuable metadata information that can be useful for organizing and managing files on your Mac. Furthermore, you can use the mdls command in scripts or workflows to automate metadata retrieval tasks.

mdls Syntax:

Terminal window
mdls [option] [parameter]

mdls Options:

OptionDescription
-hShow help message
-pSpecify the property to display metadata for
-nPrint just the metadata values, no titles
-sPrint just the metadata values, no titles and extra information

Parameters:

ParameterDescription
pathSpecify the file path to display metadata for

mdls Command Usage Examples:

Display Metadata of a File

Terminal window
mdls /Users/username/Documents/file.docx

Retrieves and displays the metadata of the specified file.

View Metadata of a PDF File

Terminal window
mdls /Users/username/Documents/document.pdf

Shows the metadata details of a PDF file located in the specified path.

Show Metadata of an Image

Terminal window
mdls /Users/username/Pictures/photo.jpg

Displays the metadata information of the image file “photo.jpg”.

Check Metadata of a Music File

Terminal window
mdls /Users/username/Music/song.mp3

Shows the metadata details of the music file “song.mp3”.

List Metadata of a Folder

Terminal window
mdls /Users/username/Documents/

Lists the metadata of all files and subdirectories within the specified folder.

How do I use mdls in MacOS?

To use the mdls command in bash, execute the following command:

Terminal window
mdls file.txt

What information does mdls provide in MacOS?

The mdls command in MacOS provides metadata information about a specified file, including details like file type, size, creation date, modification date, and more.

Terminal window
mdls document.pdf

How to display all available metadata attributes using mdls?

To display all available metadata attributes for a specific file using mdls, run the following command:

Terminal window
mdls -name *

How can I search for specific metadata attributes using mdls in MacOS?

You can search for specific metadata attributes using the mdls command by specifying the attribute name as shown in the example below.

Terminal window
mdls -name kMDItemContentType document.pdf

Can I use mdls with multiple files at once?

Yes, you can use mdls with multiple files at once by providing the file paths as arguments to the command separated by a space.

Terminal window
mdls file1.txt file2.txt

How to filter the output of mdls to display specific metadata attributes?

To filter the output of mdls and display only specific metadata attributes, use the -name option followed by the attribute name as shown in the command below.

Terminal window
mdls -name kMDItemDisplayName document.pdf

Is it possible to save the output of mdls to a file in MacOS?

Yes, you can save the output of mdls to a file by using standard output redirection in bash.

Terminal window
mdls document.pdf > metadata_info.txt

How can I get help or more information about the mdls command in MacOS?

For more information about the mdls command, you can refer to its man page by running the following command:

Terminal window
man mdls

Applications of the mdls command

  • Extracting metadata information from files
  • Investigating file attributes using Spotlight metadata
  • Scripting and automation tasks to access file metadata
  • Checking file creation and modification dates in macOS