当我用Mac OSX中内置的zip压缩器压缩文件时,它会在提取的zip中创建一个名为“__MACOSX”的额外文件夹。

我是否可以调整我的设置以避免创建此文件夹,或者我是否需要购买第三方压缩工具?

更新:我刚刚发现了一个OSX的免费应用程序,解决了我的问题:“YemuZip”

更新2:YemuZip不再是免费软件。


当前回答

这是我在使用tar命令压缩文件时避免__MACOSX目录的方法:

$ CD dir-you-want-to-archive $ find。| xargs xattr - l# <-列出所有具有特殊xattr属性的文件 ... ./conf/clamav: com.apple.quarantine: 0083;5a9018b1 ./conf/global: com.apple.quarantine: 0083;5a9018b1;Safari ./conf/web_server: com.apple.quarantine: 0083;5a9018b1

先删除属性:

找到。|xargs xattr -d com.apple.quarantine

运行find。| xargs xattr -l,确保没有任何文件具有xattr属性。然后你就可以开始了:

你是水手bz2你

其他回答

不需要的文件夹还可以通过以下方式删除:

zip -d filename.zip "__MACOSX*"

最适合我

你指的是zip命令行工具还是Finder的压缩命令?

对于zip,您可以尝试——data-fork选项。如果这不能解决问题,您可以尝试——no-extra,尽管这似乎忽略了其他可能有价值的文件元数据,如uid/gid和文件时间。

对于Finder的压缩命令,我不相信有任何选项来控制它的行为。这是一个简单的例子。

The other tool, and maybe the one that the Finder actually uses under the hood, is ditto. With the -c -k options, it creates zip archives. With this tool, you can experiment with --norsrc, --noextattr, --noqtn, --noacl and/or simply leave off the --sequesterRsrc option (which, according to the man page, may be responsible for the __MACOSX subdirectory). Although, perhaps the absence of --sequesterRsrc simply means to use AppleDouble format, which would create ._ files all over the place instead of one __MACOSX directory.

另一个可以与Automator工具一起使用的shell脚本(参见benedikt关于如何创建脚本的回答)是:

while read -r f; do
    d="$(dirname "$f")"
    n="$(basename "$f")"
    cd "$d"
    zip "$n.zip" -x \*.DS_Store -r "$n"
done

不同之处在于,这段代码直接压缩选定的文件夹,而不包含macOS特定的文件(而不是先压缩后删除)。

当我遇到这个问题时,我已经从命令行完成了:

zip file.zip uncompressed

编辑,在许多反对票后:我使用这个选项一段时间前,我不知道我从哪里学到的,所以我不能给你一个更好的解释。克里斯·约翰逊的答案是正确的,但我不会删除我的。正如一个评论所说,它更准确地反映了OP的要求,因为它在没有这些文件的情况下进行压缩,而不是从压缩文件中删除它们。我发现它也更容易记住。

在你想要压缩的文件夹中,在终端:

zip -r -X Archive.zip *

其中-X表示:排除那些不可见的Mac资源文件,如“_MACOSX”或“。“_Filename”和“。ds”存放文件

注意:将只适用于文件夹和后续的文件夹树,你在,必须有*通配符。