54

Is there any way to get all of the metadata associated with a file in Terminal? By "metadata" I mean things metadata and properties that are not stored in nor derived from the file's contents (i.e., checksum, UTD, image resolution, etc.), but rather reside in the filesystem's data about the file (i.e., last time changed, inode, permissions, extended attributes, etc.).

1
  • Check out the 'stat' command, and 'mdls' for spotlight metadata. 'ls' also has '-e' and '-@' options that give more info when used with the '-l' option.
    – mtklr
    Commented Jan 7, 2016 at 14:24

2 Answers 2

93

This response might be late, but hopefully it will help someone.

There are numerous ways to view metadata in the terminal on an Apple computer:

  1. mdls path/file.extension

    • mdls stands for Metadata List and you can look at the man pages (man mdls) to learn how to use it.
  2. xattr path/file.extension

    • xattr stands for Extended Attributes. This can be used to display and edit extended attributes of files.
    • xattr -l path/file.extension causes the attribute names and values to be displayed. However, I've noticed that, at least on macOS, it seems that this only displays user-added data.
  3. ls -l@ path/file.extension

    • ls is a powerful terminal listing utility. In its simplest form it lists the current directory contents. However, as you can see here you can list more than that.
  4. exiftool path/file.extension

    • You need to install exiftool separately if you haven't already. For example, if you use brew, you can do brew install exiftool.
    • exiftool is a useful utility for viewing and messing around with file metadata.
  5. sips -g all path/file.extension (for images)

    • sips and identify are both for reading image metadata/info.
  6. identify -verbose path/file.extension (for images)

Depending on your desired application, one of these might be more appropriate or convenient than the others. However, it should be noted that these all show different things, even if slightly.

3
  • 3
    👏👏👏 This answer is *chef's kiss* perfect. Thank you, exactly what I was looking for, and more!
    – dossy
    Commented Nov 17, 2021 at 19:53
  • Are there built-in tools on macOS to edit metadata?
    – user150109
    Commented Oct 1 at 14:07
  • @user150109 sips can with the setProperty option but it probably is restricted to images. xattr probably can but FWIW, I find it unpleasant to work with.
    – Mockman
    Commented Dec 7 at 20:25
2

I mean, ls can give you a lot of information with the -l flag

[email protected]:~# ls -l .bashrc
total 6980
-rw-r-----. 1 user   user    14499 Jan  6 17:59 .bashrc

There is your last touched, owner, group, and permissions; then there is md5sum for that:

[email protected]:~# md5sum .bashrc
2aa4f74675fa647d23d3dbbe31e9c4d1  .bash_history
1
  • adding a -i flag to the ls invocation will print inode information as well
    – crasic
    Commented Jan 7, 2016 at 6:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .