How to View & Remove Extended Attributes from a File on Mac OS

May 3, 2018 - 3 Comments

Terminal in macOS

Extended Attributes are metadata components that can be unique to specific files and file types on Mac OS. Those extended attributes can be anything from identifying data about the file itself, to quarantine information, origin data, label information, amongst other types of metadata.

Sometimes, advanced Mac users may review extended attributes for a file, or even wish to remove extended attributes from a file or directory for a variety of reasons, and either of those tasks can be accomplished through the command line with the bundled xattr tool in Mac OS. This tutorial will walk through how to both view and remove extended attributes from a file on a Mac.

This is an advanced topic that is really only relevant to advanced users who are already familiar with extended attributes and have a particular reason to want to remove them from a file. If you’re not sure what extended attributes are, why they may (or may not) matter, or why you might want to (or not want to) remove them, this is not for you.

How to View Extended Attributes of a File in Mac OS

The xattr command has been around in Mac OS and Mac OS X for a long time and thus this should work the same on virtually all vaguely modern versions of system software:

  1. Open the Terminal app, found in /Applications/Utilities/
  2. Use the xattr command like so, pointing at the file path to inspect extended attributes for
  3. xattr ~/Desktop/samplefile.jpg

  4. Hit Return to view the extended attributes for the file specified

For example, you might see something like the following after executing the command:

xattr ~/Desktop/samplefile.jpg
com.apple.metadata:kMDItemIsScreenCapture
com.apple.metadata:kMDItemScreenCaptureGlobalRect
com.apple.metadata:kMDItemScreenCaptureType
com.apple.metadata:kMDItemWhereFroms
com.apple.quarantine

In this case you’ll see metadata information that can be used by Spotlight and the Finder search features, as well as quarantine data which may be tied to data downloaded from the web, or brought onto the Mac through a third party app or source. And yes, that is the same quarantine data from that tells you whether or not you see the app “can’t be opened because it is from an unidentified developer” Gatekeeper message when opening certain applications or files – that’s a commonly encountered practical example of an extended attribute.

How to Remove Extended Attributes from a File on Mac

Still in the Terminal app? If not, relaunch Terminal application to begin:

  1. Find the extended attribute you want to remove from the file using the previous step, in this example let’s assume it’s “kMDItemIsScreenCapture”
  2. Use xattr with the -d flag on the file like so:
  3. xattr -d com.apple.metadata:kMDItemIsScreenCapture ~/Desktop/samplefile.jpg

  4. Hit Return to strip the defined extended attribute from the file as specified by the path

In this example, removing “com.apple.metadata:kMDItemIsScreenCapture” from the samplefile.jpg file strips out the screenshot identifier, which you may recognize from this tip for finding and showing all screen shot files on a Mac, which relies on that extended attribute attached to screenshot files in order to locate them. By removing that extended attribute, the file would no longer show up in such a search. Note that using a tool like ImageOptim to strip EXIF metadata from images and pictures does not also remove extended attribute metadata from the images, it only removes the EXIF data – the two are separate.

You can use the xattr tool to view and remove extended attributes on files, directories, and symbolic links this way, and you can use wildcards to apply the extended attribute removal to multiple files as needed.

This is really not something that should be of relevance to most casual Mac users, but for advanced Mac users, tinkerers, developers, sysadmins, information security workers, and many others, being able to view or modify extended attributes can be helpful for particular reasons.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

3 Comments

» Comments RSS Feed

  1. RegB says:

    Thanks for this particular tip (and all others too). Having been a former Windows user and quite informed about file attributes I have at times wondered about Mac OS files and attributes. Did they use them?
    Thank you osxdaily team,
    RegB

  2. Bruce K. says:

    These extended attributes are not very well known or explained. Are some of these the data we see when we right-click-get_info in the Finder?

    I see a place for comments; or with images things like the type of coding, or dimensions.

    Are these all extended attributes, and where are they defined? Are there fixed attributes or can we make our own up? And how does Spotlight interact with this information.

    There is so much power here, yet I’ve never run across anything that helps me as a Max owner and user leverage that value?

  3. Bruce K. says:

    Also, I wonder wondering how and where are they stored logically and physically. Are they in the inode of the file, part of the file’s data, or stored in some other way. Is there any other way to get to this data than this clumsy command?

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac