首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >递归xattr严重失败

递归xattr严重失败
EN

Stack Overflow用户
提问于 2017-04-08 16:30:05
回答 2查看 1.3K关注 0票数 1

我一直在试图找到一种方法来递归地删除某些文件的所有xattr,但是,似乎没有一个以往方法不再工作了;可能也有一个新引入的错误?

代码语言:javascript
复制
$ xattr -rc .
option -r not recognized

$ xattr -c .
option -c not recognized

..and,现在是大结局!

代码语言:javascript
复制
$ 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

哦,看,它在淤泥中找到了一个xattr .知道如何、什么或谁如此严重地破坏了xattr工具是很有趣的。我只需要递归地删除扩展属性,真的!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-08 17:17:37

您似乎在/usr/local/bin/xattr中安装了一个非标准的xattr命令( macOS附带的标准命令是/usr/bin/xattr)。这些都是Python错误,所以可能是这一个?无论如何,它不使用与标准语法相同的语法,因此安装它会造成混乱;我建议将其删除或将其重命名为不同的语法;否则,可能会破坏任何尝试使用xattr的脚本(您的脚本或系统脚本)。

票数 5
EN

Stack Overflow用户

发布于 2019-08-10 20:56:53

这也发生在我身上。我相信是因为我的$PATH

代码语言:javascript
复制
/usr/local/bin:/usr/bin

我的user local bin先于我的system usr/bin

多亏了这些帖子,我发现了这个问题。

xattr安装在两个地点。

显示目标是内置的、函数、别名还是外部可执行文件。(来源)/

代码语言:javascript
复制
type -a xattr
# xattr is /usr/local/bin/xattr
# xattr is /usr/bin/xattr

当然,它们是不同的。

代码语言:javascript
复制
/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.

代码语言:javascript
复制
/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

因此,如果您出于任何原因都想保留这两种情况,那么您可以这样显式地调用它们:

代码语言:javascript
复制
/usr/bin/xattr -lr ~

/usr/local/bin/xattr -l ~
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43297564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档