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:
Section titled “mdls Syntax:”mdls [option] [parameter]
mdls Options:
Section titled “mdls Options:”Option | Description |
---|---|
-h | Show help message |
-p | Specify the property to display metadata for |
-n | Print just the metadata values, no titles |
-s | Print just the metadata values, no titles and extra information |
Parameters:
Section titled “Parameters:”Parameter | Description |
---|---|
path | Specify the file path to display metadata for |
mdls Command Usage Examples:
Section titled “mdls Command Usage Examples:”Display Metadata of a File
Section titled “Display Metadata of a File”mdls /Users/username/Documents/file.docx
Retrieves and displays the metadata of the specified file.
View Metadata of a PDF File
Section titled “View Metadata of a PDF File”mdls /Users/username/Documents/document.pdf
Shows the metadata details of a PDF file located in the specified path.
Show Metadata of an Image
Section titled “Show Metadata of an Image”mdls /Users/username/Pictures/photo.jpg
Displays the metadata information of the image file “photo.jpg”.
Check Metadata of a Music File
Section titled “Check Metadata of a Music File”mdls /Users/username/Music/song.mp3
Shows the metadata details of the music file “song.mp3”.
List Metadata of a Folder
Section titled “List Metadata of a Folder”mdls /Users/username/Documents/
Lists the metadata of all files and subdirectories within the specified folder.
How do I use mdls in MacOS?
Section titled “How do I use mdls in MacOS?”To use the mdls command in bash, execute the following command:
mdls file.txt
What information does mdls provide in MacOS?
Section titled “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.
mdls document.pdf
How to display all available metadata attributes using mdls?
Section titled “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:
mdls -name *
How can I search for specific metadata attributes using mdls in MacOS?
Section titled “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.
mdls -name kMDItemContentType document.pdf
Can I use mdls with multiple files at once?
Section titled “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.
mdls file1.txt file2.txt
How to filter the output of mdls to display specific metadata attributes?
Section titled “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.
mdls -name kMDItemDisplayName document.pdf
Is it possible to save the output of mdls to a file in MacOS?
Section titled “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.
mdls document.pdf > metadata_info.txt
How can I get help or more information about the mdls command in MacOS?
Section titled “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:
man mdls
Applications of the mdls command
Section titled “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