如何从目录中递归清除(删除)macos 扩展属性?

bro*_*its 6 mac file-attributes command-line

我从 GitHub ( Homebrew/brew )下载了一个存档并将其解压到下面的临时目录中/root(在 的帮助下sudo)。如果我这样做,ls -l我会看到一个扩展属性:

total 0
drwxr-xr-x@ 16 root  wheel  512 Jul  2 09:30 brew-master
Run Code Online (Sandbox Code Playgroud)

如果我这样做ls -l@(感谢这个问题答案),我会得到以下输出:

total 0
drwxr-xr-x@ 16 root  wheel  512 Jul  2 09:30 brew-master
    com.apple.quarantine     59 
Run Code Online (Sandbox Code Playgroud)

如果我这样做,ls -l@ brew-master我会得到以下输出:

total 48
-rw-r--r--@  1 root  wheel    98 Jul  2 09:30 CHANGELOG.md
    com.apple.quarantine      59 
-rw-r--r--@  1 root  wheel  3161 Jul  2 09:30 CODE_OF_CONDUCT.md
    com.apple.quarantine      59 
-rw-r--r--@  1 root  wheel   720 Jul  2 09:30 CONTRIBUTING.md
    com.apple.quarantine      59 
-rw-r--r--@  1 root  wheel  1334 Jul  2 09:30 LICENSE.txt
    com.apple.quarantine      59 
drwxr-xr-x@  7 root  wheel   224 Jul  2 09:30 Library
    com.apple.quarantine      59 
-rw-r--r--@  1 root  wheel  7374 Jul  2 09:30 README.md
    com.apple.quarantine      59 
drwxr-xr-x@  3 root  wheel    96 Jul  2 09:30 bin
    com.apple.quarantine      59 
drwxr-xr-x@  5 root  wheel   160 Jul  2 09:30 completions
    com.apple.quarantine      59 
drwxr-xr-x@ 48 root  wheel  1536 Jul  2 09:30 docs
    com.apple.quarantine      59 
drwxr-xr-x@  5 root  wheel   160 Jul  2 09:30 manpages
    com.apple.quarantine      59 
Run Code Online (Sandbox Code Playgroud)

这个问题答案告诉我如何xattr -d清除属性,但它只适用于单个文件或目录条目。

如何递归地清除该属性?

PS 如果我将下载的文件解压缩到非根子目录中,我似乎会获得类似的隔离属性。

bro*_*its 8

快速简单的解决方案(结合这个问题答案这篇博客文章):

xattr -cr brew-master
Run Code Online (Sandbox Code Playgroud)

sudo当且仅当它位于根目录内时才使用)

同一篇博客文章中稍微完善的解决方案:

xattr -r -d com.apple.quarantine brew-master
Run Code Online (Sandbox Code Playgroud)

更好的解决方案是使用命令行工具来获取和提取此类存档,以便从一开始就避免此类问题。这种解决方案是我关于如何手动安装 Homebrew 的答案的一部分。