How do I remove the "extended attributes" on a file in Mac OS X? – Dev

The best answers to the question “How do I remove the "extended attributes" on a file in Mac OS X?” in the category Dev.


I have an AppleScript script that runs a stress test. Part of the test is to open, save, and close certain files. Somehow, the files have picked up some “extended attributes” that prohibit the files from being saved. That causes the stress test to fail.

How do I remove the extended attributes?


Removing a Single Attribute on a Single File

See Bavarious’s answer.

To Remove All Extended Attributes On a Single File

Use xattr with the -c flag to “clear” the attributes:

xattr -c yourfile.txt

To Remove All Extended Attributes On Many Files

To recursively remove extended attributes on all files in a directory, combine the -c “clear” flag with the -r recursive flag:

xattr -rc /path/to/directory

A Tip for Mac OS X Users

Have a long path with spaces or special characters?

Open and start typing xattr -rc, include a trailing space, and then then drag the file or folder to the window and it will automatically add the full path with proper escaping.


Use the xattr command. You can inspect the extended attributes:

$ xattr s.7z

and use the -d option to delete one extended attribute:

$ xattr -d s.7z
$ xattr s.7z

you can also use the -c option to remove all extended attributes:

$ xattr -c s.7z
$ xattr s.7z

xattr -h will show you the command line options, and xattr has a man page.


Answer (Individual Files)

1. Showcase keys to use in selection.

xattr ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png

2. Pick a Key to delete.

xattr -d ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
xattr -d kMDItemIsScreenCapture ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png

3. Showcase keys again to see they have been removed.

xattr -l ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png

4. Lastly, REMOVE ALL keys for a particular file

xattr -c ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png

Answer (All Files In A Directory)

1. Showcase keys to use in selection.

xattr -r ~/Desktop

2. Remove a Specific Key for EVERY FILE in a directory

xattr -rd ~/Desktop

3. Remove ALL keys on EVERY FILE in a directory

xattr -rc ~/Desktop

WARN: Once you delete these you DON’T get them back!


I wanted to address the error’s people are getting.
Because the errors drove me nuts too…
On a mac if you install xattr in python, then your environment may have an issue.

There are two different paths on my mac for xattr

type -a xattr

    # xattr is /usr/local/bin/xattr    # PYTHON Installed Version
    # xattr is /usr/bin/xattr          # Mac OSX Installed Version

So in one of the example’s where -c will not work in xargs is because in bash you default to the non-python version.

Works with -c

/usr/bin/xattr -c

Does NOT Work with -c

/usr/local/bin/xattr -c
    # option -c not recognized

My Shell/Terminal defaults to /usr/local/bin/xattr because my $PATH
/usr/local/bin: is before /usr/bin: which I believe is the default.

I can prove this because, if you try to uninstall the python xattr you will see:

pip3 uninstall xattr
Uninstalling xattr-0.9.6:
  Would remove:
Proceed (y/n)?


To Fix option -c not recognized Errors.

  1. Uninstall any Python xattr you may have: pip3 uninstall xattr
  2. Close all Terminal windows & quit Terminal
  3. Reopen a new Terminal window.
  4. ReRun xattr command and it should now work.


If you want to keep the Python xattr then use


for any Shell commands in Terminal


Python’s version of xattr doesn’t handle images at all:

Good-Mac:~ JayRizzo$ xattr ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
    # Traceback (most recent call last):
    #   File "/usr/local/bin/xattr", line 8, in <module>
    #     sys.exit(main())
    #   File "/usr/local/lib/python3.7/site-packages/xattr/", line 196, in main
    #     attr_value = attr_value.decode('utf-8')
    # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 2: invalid start byte

Good-Mac:~ JayRizzo$ /usr/bin/xattr ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png

Man Pages

MAN PAGE for OSX xattr

MAN PAGE for Python xattr VERSION 0.6.4

NOTE: I could not find the python help page for current VERSION 0.9.6

Thanks for Reading!


Try using:

xattr -rd directoryname

This takes care of recursively removing the pesky attribute everywhere.