Skip to content

MacOS GetFileInfo command

The MacOS getfileinfo command is a powerful tool that allows users to retrieve detailed metadata information about files and directories on their system. This command provides essential information such as file type, creator code, file size, and modification date. By using getfileinfo, users can easily access crucial details about their files without having to open them individually. This command is especially useful for users who need to quickly gather information about multiple files or for scripting purposes. With getfileinfo, MacOS users can efficiently manage and organize their files based on their metadata attributes.

GetFileInfo Syntax:

Terminal window
mdls [option] [parameter]

Options:

OptionDescription
-nameDisplay the specified metadata property
-rawDisplay raw value of metadata property
-plistOutput in plist format
-nullSeparate attribute-value pairs with nulls
-humanReadableConvert file sizes to human-readable strings

Parameters:

ParameterDescription
file_pathPath to the file for which metadata is needed

Check File Information

Terminal window
getfileinfo -a ~/Documents/example.txt

This command displays all available information about the file “example.txt” located in the “Documents” directory.

Display Only File Type

Terminal window
getfileinfo -t ~/Pictures/photo.jpg

This command shows only the file type of the specified image “photo.jpg” in the “Pictures” directory.

Get Extended Attributes

Terminal window
getfileinfo -x ~/Downloads/document.pdf

Use this command to retrieve the extended attributes of the file “document.pdf” located in the “Downloads” directory.

Show Resource Fork Information

Terminal window
getfileinfo -r ~/Music/song.mp3

By executing this command, you can view the resource fork information of the file “song.mp3” in the “Music” directory.

## GetFileInfo Usage:
### Check File Information
```bash
getfileinfo -a ~/Documents/example.txt

This command displays all available information about the file “example.txt” located in the “Documents” directory.

Display Only File Type

Terminal window
getfileinfo -t ~/Pictures/photo.jpg

This command shows only the file type of the specified image “photo.jpg” in the “Pictures” directory.

Get Extended Attributes

Terminal window
getfileinfo -x ~/Downloads/document.pdf

Use this command to retrieve the extended attributes of the file “document.pdf” located in the “Downloads” directory.

Show Resource Fork Information

Terminal window
getfileinfo -r ~/Music/song.mp3

By executing this command, you can view the resource fork information of the file “song.mp3” in the “Music” directory.

How do I use getfileinfo in MacOS?

To use the getfileinfo command in MacOS, execute the following command:

Terminal window
getfileinfo --name /path/to/file

How can I check the file type with getfileinfo in MacOS?

To check the file type using getfileinfo in MacOS, run the following command:

Terminal window
getfileinfo --fileType /path/to/file

How do I display the file creator and type information with getfileinfo in MacOS?

To display the file creator and type information using getfileinfo in MacOS, use the following command:

Terminal window
getfileinfo --creatorType /path/to/file

How can I get information about the file size using getfileinfo in MacOS?

To retrieve information about the file size with getfileinfo in MacOS, enter the following command:

Terminal window
getfileinfo --size /path/to/file

How do I show all available information about a file using getfileinfo in MacOS?

To display all available information about a file with getfileinfo in MacOS, use the following command:

Terminal window
getfileinfo --full /path/to/file

How can I get the file flags using getfileinfo in MacOS?

To obtain the file flags using getfileinfo in MacOS, execute the following command:

Terminal window
getfileinfo --flags /path/to/file

How do I view the file metadata attributes with getfileinfo in MacOS?

To view the file metadata attributes using getfileinfo in MacOS, run the following command:

Terminal window
getfileinfo --attributes /path/to/file

Applications of the GetFileInfo command

  • Retrieving information about files in the MacOS system.
  • Checking the file type, creator, and other attributes.
  • Viewing details like file size, creation date, and modification date.
  • Assisting in file management and organization.
  • Verifying file information for troubleshooting or maintenance purposes.
  • Providing metadata details for files when needed.