tam*_*mes 250 macos attributes
我有一个运行压力测试的AppleScript脚本.部分测试是打开,保存和关闭某些文件.不知何故,文件已经选择了一些禁止文件保存的"扩展属性".这导致压力测试失败.
如何删除扩展属性?
小智 377
使用该xattr
命令.您可以检查扩展属性:
$ xattr s.7z
com.apple.metadata:kMDItemWhereFroms
com.apple.quarantine
Run Code Online (Sandbox Code Playgroud)
并使用该-d
选项删除一个扩展属性:
$ xattr -d com.apple.quarantine s.7z
$ xattr s.7z
com.apple.metadata:kMDItemWhereFroms
Run Code Online (Sandbox Code Playgroud)
您还可以使用该-c
选项删除所有扩展属性:
$ xattr -c s.7z
$ xattr s.7z
Run Code Online (Sandbox Code Playgroud)
xattr -h
将显示命令行选项,xattr有一个手册页.
cwd*_*cwd 99
见Bavarious的回答.
使用xattr
与-c
标志"明确"的属性:
xattr -c yourfile.txt
Run Code Online (Sandbox Code Playgroud)
要以递归方式删除目录中所有文件的扩展属性,请将-c
"clear"标志与-r
递归标志结合使用:
xattr -rc /path/to/directory
Run Code Online (Sandbox Code Playgroud)
有空格或特殊字符的长路径?
打开Terminal.app
并开始输入xattr -rc
,包括尾随空格,然后将文件或文件夹拖到Terminal.app
窗口,它将自动添加正确转义的完整路径.
小智 23
尝试使用:
xattr -rd com.apple.quarantine directoryname
Run Code Online (Sandbox Code Playgroud)
这需要在任何地方递归地删除讨厌的属性.
Jay*_*zzo 16
xattr ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
# com.apple.FinderInfo
# com.apple.lastuseddate#PS
# com.apple.metadata:kMDItemIsScreenCapture
# com.apple.metadata:kMDItemScreenCaptureGlobalRect
# com.apple.metadata:kMDItemScreenCaptureType
Run Code Online (Sandbox Code Playgroud)
xattr -d com.apple.lastuseddate#PS ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
xattr -d kMDItemIsScreenCapture ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
Run Code Online (Sandbox Code Playgroud)
xattr -l ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
# com.apple.FinderInfo
# com.apple.metadata:kMDItemScreenCaptureGlobalRect
# com.apple.metadata:kMDItemScreenCaptureType
Run Code Online (Sandbox Code Playgroud)
xattr -c ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
Run Code Online (Sandbox Code Playgroud)
xattr -r ~/Desktop
Run Code Online (Sandbox Code Playgroud)
xattr -rd com.apple.FinderInfo ~/Desktop
Run Code Online (Sandbox Code Playgroud)
xattr -rc ~/Desktop
Run Code Online (Sandbox Code Playgroud)
警告:一旦你删除了这些,你就不会再找回来了!
故障错误:没有撤消。
我想解决人们遇到的错误。
因为这些错误也让我发疯了......
在 Mac 上,如果你安装xattr
在 python 中,那么你的环境可能有问题。
我的 mac 上有两条不同的路径
xattr
type -a xattr
# xattr is /usr/local/bin/xattr # PYTHON Installed Version
# xattr is /usr/bin/xattr # Mac OSX Installed Version
Run Code Online (Sandbox Code Playgroud)
因此,在示例之一-c
中 xargs 不起作用的地方是因为在 bash 中您默认使用非 Python 版本。
-c
/usr/bin/xattr -c
Run Code Online (Sandbox Code Playgroud)
-c
/usr/local/bin/xattr -c
# option -c not recognized
Run Code Online (Sandbox Code Playgroud)
我的shell /终端默认为/ usr / local / bin目录/ XATTR,因为我$PATH
/usr/local/bin:
是之前/usr/bin:
我认为是默认它。
我可以证明这一点,因为如果您尝试卸载 python,xattr
您将看到:
pip3 uninstall xattr
Uninstalling xattr-0.9.6:
Would remove:
/usr/local/bin/xattr
/usr/local/lib/python3.7/site-packages/xattr-0.9.6.dist-info/*
/usr/local/lib/python3.7/site-packages/xattr/*
Proceed (y/n)?
Run Code Online (Sandbox Code Playgroud)
修复option -c not recognized
错误。
xattr
您可能拥有的任何 Python :pip3 uninstall xattr
Terminal
窗口并退出Terminal
Terminal
窗口。xattr
命令,它现在应该可以工作了。或者
如果你想保留 Python
xattr
然后使用
/usr/bin/xattr
Run Code Online (Sandbox Code Playgroud)
对于任何Shell
命令Terminal
Python 的版本xattr
根本不处理图像:
Good-Mac:~ JayRizzo$ xattr ~/Desktop/screenshot\ 2019-10-23\ at\ 010212.png
# com.apple.FinderInfo
# 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/tool.py", 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
# com.apple.FinderInfo
# com.apple.lastuseddate#PS
# com.apple.metadata:kMDItemIsScreenCapture
# com.apple.metadata:kMDItemScreenCaptureGlobalRect
# com.apple.metadata:kMDItemScreenCaptureType
Run Code Online (Sandbox Code Playgroud)
注:我无法找到Python的帮助页面当前版本0.9.6
谢谢阅读!
另一种递归方法:
# change directory to target folder:
cd /Volumes/path/to/folder
# find all things of type "f" (file),
# then pipe "|" each result as an argument (xargs -0)
# to the "xattr -c" command:
find . -type f -print0 | xargs -0 xattr -c
# Sometimes you may have to use a star * instead of the dot.
# The dot just means "here" (whereever your cd'd to
find * -type f -print0 | xargs -0 xattr -c
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
187204 次 |
最近记录: |