1

I've been trying to figure out a way to recursively remove all of the xattr for some files, however, none of the previous methods seem to work anymore; there might be a newly introduced bug too?

$ xattr -rc .
option -r not recognized

$ xattr -c .
option -c not recognized

..and now the grand finale!

$ find . -exec xattr -l {} \;
com.apple.FinderInfo:
Traceback (most recent call last):
  File "/usr/local/bin/xattr", line 11, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/xattr/tool.py", line 200, in main
    print(_dump(attr_value))
  File "/Library/Python/2.7/site-packages/xattr/tool.py", line 77, in _dump
    printable = s.translate(_FILTER)
TypeError: character mapping must return integer, None or unicode

Oh look it found an xattr amongst the muck... it would be interesting to know how, what or who destroyed the xattr tool so badly. I just need to recursively remove extended attributes, really!

Community
  • 1
  • 1
l'L'l
  • 44,951
  • 10
  • 95
  • 146

2 Answers2

5

You appear to have a nonstandard xattr command installed in /usr/local/bin/xattr (the standard one that ships with macOS is /usr/bin/xattr). Those are Python errors, so maybe it's this one? Anyway, it doesn't use the same syntax as the standard one, so having it installed is going to cause confusion; I'd recommend either removing it or renaming it to something distinct; otherwise it's likely to break any scripts (yours or system) that try to use xattr.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
1

This happened to me as well. and I believe is due to my $PATH

/usr/local/bin:/usr/bin

My user local bin comes before my system usr/bin.

Thanks to these posts I figured out the problem.

xattr was installed in two locations.

Show whether the target is a builtin, a function, an alias or an external executable.(Source) /

type -a xattr
# xattr is /usr/local/bin/xattr
# xattr is /usr/bin/xattr

and they are different for sure.

/usr/local/bin/xattr -h
usage: xattr [-slz] file [file ...]
       xattr -p [-slz] attr_name file [file ...]
       xattr -w [-sz] attr_name attr_value file [file ...]
       xattr -d [-s] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
  -h: print this help
  -s: act on symbolic links themselves rather than their targets
  -l: print long format (attr_name: attr_value)
  -z: compress or decompress (if compressed) attribute value in zip format

VS.

/usr/bin/xattr -h
usage: xattr [-l] [-r] [-s] [-v] [-x] file [file ...]
       xattr -p [-l] [-r] [-s] [-v] [-x] attr_name file [file ...]
       xattr -w [-r] [-s] [-x] attr_name attr_value file [file ...]
       xattr -d [-r] [-s] attr_name file [file ...]
       xattr -c [-r] [-s] file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.
The fifth form (-c) deletes (clears) all xattrs.

options:
  -h: print this help
  -l: print long format (attr_name: attr_value and hex output has offsets and
      ascii representation)
  -r: act recursively
  -s: act on the symbolic link itself rather than what the link points to
  -v: also print filename (automatic with -r and with multiple files)
  -x: attr_value is represented as a hex string for input and output

So, if you do want to keep both for whatever reason, then you can just call them explicitly like so:

/usr/bin/xattr -lr ~

/usr/local/bin/xattr -l ~
JayRizzo
  • 3,234
  • 3
  • 33
  • 49